这可以使用push方法完成。例如,
let veggies = ["Onion", "Raddish"]; veggies.push("Cabbage"); console.log(veggies);
这将给出输出-
["Onion", "Raddish", "Cabbage"]
您还可以使用它同时推送多个项目,因为它支持可变数量的参数。例如,
let veggies = ["Onion", "Raddish"]; veggies.push("Cabbage", "Carrot", "Broccoli"); console.log(veggies);
这将给出输出-
["Onion", "Raddish", "Cabbage", "Carrot", "Broccoli"]