如何通过索引值删除数组元素

时间:2015-05-27 17:51:52

标签: javascript arrays json

我需要通过索引值删除数组元素。我有索引值,我只需要拼接它。 customSeriesIndexMatch是我需要从customSeriesSums.data

中删除的索引号

fiddle

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

2 个答案:

答案 0 :(得分:3)

所以只需使用splice方法:

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

答案 1 :(得分:2)

查看splice docs

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