当我尝试在数组中调用console.log字符串时,它会在单独的行上打印每个文本字符和逗号分隔符:
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++;
}
当我查看控制台时,这些是我的结果:
答案 0 :(得分:0)
你被全球window.name咬了。将您的变量更改为其他变量或将其从全局范围中删除。
答案 1 :(得分:0)
name
是一个保留的javascript字词。
var names = ["add","bas","cun","deh"];
var sizes = [2,5,7,9];
var prices = [250,150,25,60];
console.log(names.map((n, i) => [n, sizes[i], prices[i]].join(' ')).join('\n'));