我想问如何将数组添加到另一个数组的末尾,但是新添加的 数组在一个索引中 例如,如果我想添加
fruits=["banana","grape"]
到
fruits=["banana","grape",["green","red","yellow"]]
我希望结果像
["banana","grape","green","red","yellow"]
而不是
typeValidator
答案 0 :(得分:1)
如果您想始终将数组添加到数组的末尾,则可以像这样使用.push()
:
let apples = ["green","red","yellow"];
let fruits = ["banana","grape"];
fruits.push(apples); // appends the array apples to the end of fruits
console.log(fruits);