delete addon_categories[index];
如果索引为 1,则此语句会在数组中留下未定义的占位符。
[{Object}, undefined]
如何解决这个问题?
最佳答案
试试这个:
if (index > -1) {
addon_categories.splice(index, 1);
}
使用delete
关键字,它将设置undefined
,不会删除元素完成其预期的行为。
关于javascript - 删除 arrayItem[index] 使元素占位符保持未定义状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45342086/