var guests = ["john", "bob", "marie"]; var arrayLength = guests.length; for(var i=0;i<arrayLength && i<5;i++){ console.log(guests[i] + ", "); } //outputs "john, bob, marie"