📌  相关文章
📜  附加到数组检查是否存在 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:35.199000             🧑  作者: Mango

代码示例3
var newItem = "NEW_ITEM_TO_ARRAY";
var array = ["OLD_ITEM_1", "OLD_ITEM_2"];

array.indexOf(newItem) === -1 ? array.push(newItem) : console.log("This item already exists");

console.log(array)