Sausejii Sausejii - 16 days ago 6
Javascript Question

Javascript console.log strings printing each character of an array on single lines

When I try to console.log strings in an array it prints each text character and the comma separators on a separate line:

var name = ["add","bas","cun","deh"];
var size = [2,5,7,9];
var price = [250,150,25,60];
var count = 0;
var mVar = 4;
var nameLen = name.length;

while (count < mVar) {

var maxSize = Math.max.apply(null, size);
var posVar = size.indexOf(maxSize);
console.log(name[posVar] + " " + size[posVar] + " " + price[posVar]);
size[posVar] = null
count++;
}


When I view the console, these are my results:

results

Answer

You got bitten by global window.name. Change your variable to something else or get it out of the global scope.

Comments