我是javascript新手。我尝试过这样的代码
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var fruit_kiwi = "Kiwi";
fruits.push(fruit_kiwi);
console.log(fruits);
我需要这样的输出 “香蕉,橙,苹果,芒果,猕猴桃” 但是我的输出是这样的 “香蕉,橘子,苹果,芒果”,“猕猴桃” 谁能帮我如何将值添加到数组中?
答案 0 :(得分:1)
我想您所需要的只是.join()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var fruit_kiwi = "Kiwi";
fruits.push(fruit_kiwi);
console.log(fruits.join(","));