-2
我正在從javascript數組中刪除。刪除數組後重新排序。從Javascript陣列重新排序
Array [ Object, Object, Object, Object, Object, Object ];
0 Object
d:17065
1 Object
d:17156
2 Object
d:17246
3 Object
d:17065
4 Object
d:17156
5 Object
d:17338
for(d = 0; d < delete_array.length; d++)
{
data_array[0].splice(delete_array[d],1);
}
經過上述刪除。數組更改爲。
Array [ Object, Object, Object ];
0 Object
d:17156
1 Object
d:17065
2 Object
d:17246
3 Object
如何防止這種情況發生?
使用'data_array中[0] = data_array中[0] .filter(X =>!delete_array.includes(X))' – Rajesh
是真不明白什麼是您預期的輸出中。你能提供你想要的輸出嗎? – rakwaht
'splice'將索引作爲第一個參數。 – ASDFGerte