Reputation: 97
So when I execute this code, it adds a space between names[i] and the string?
var names = ["Bob", "Daniel", "John", "Jimmy", "Joseph"]
for (var i = 0; i < names.length; i ++) {
console.log("I know someone called",names[i])
}
I'm new to this.
Upvotes: 2
Views: 54
Reputation: 2961
That's just the behaviour of console.log
. Each parameter you pass will be separated by a space, and is expected (see here) - if you don't want the space, try:
console.log("I know someone called" + names[i]);
By using the +
, you are directly concatenating the strings and ensuring there is no space
Upvotes: 5