Sausejii Sausejii - 1 year ago 86
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

When I view the console, these are my results:


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download