gpt4 book ai didi

javascript - 如何通过其索引值删除数组的元素

转载 作者:行者123 更新时间:2023-11-30 08:36:58 26 4
gpt4 key购买 nike

我需要根据索引值删除数组中的一个元素。我已经有了索引值我只需要拼接它。 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

最佳答案

所以只需使用 splice方法:

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

关于javascript - 如何通过其索引值删除数组的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30489729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com