簡體   English   中英

如何通過其索引值刪除數組的元素

[英]how to remove a element of a array by its index value

我需要通過其索引值刪除數組的元素。 我已經有了索引值,只需要拼接即可。 customSeriesIndexMatch是我需要從customSeriesSums.data中刪除的索引號

小提琴

var dataPointSum = 101100;
console.log(customSeriesSums[0].data);

 // loop through customSeriesSums and match with dataPointSum
    var index = customSeriesSums[0].data.indexOf(dataPointSum);
    var customSeriesIndexMatch = index + 1
   console.log("DataPointSum : " + dataPointSum + " " + "Matched with customSeriesSum Index : " + customSeriesIndexMatch);

 // now I need to remove the customSeriesSums.data array by its index that equals customSeriesIndexMatch

因此,只需使用splice方法:

customSeriesSums[0].data.splice( customSeriesIndexMatch, 1 );

查看拼接文檔

customSeriesSums[0].data.splice( customSeriesIndexMatch,1 );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM