简体   繁体   English

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

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

I need to remove a element of a array by its index value. 我需要通过其索引值删除数组的元素。 I have the index value already I just need to splice it. 我已经有了索引值,只需要拼接即可。 The customSeriesIndexMatch is the index number that i need to remove from customSeriesSums.data 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 );

查看拼接文档

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据其值之一选择数组索引元素? - How to select a Array index element with respect of its one of Value? 如何删除数组中索引前后的元素 - How to remove element before and after the index in an array 通过其索引删除数组对象 - remove array object by its index 如何通过值删除数组中的对象? - How to remove objects in an array by its value? JavaScript | 如何使用数组的值而不是索引删除数组的元素? - JavaScript | How can I remove an element of an array using it's value instead of it's index? 在jquery中如何通过索引[“key”]或值删除数组元素 - In jquery how do I remove an array element either via index[“key”] or value 如何通过索引 position 从存储在本地存储中的数组中删除 object - How to remove an object by its index position from an array stored in the localstorage jQuery:在Array中记录元素更改并通过其索引检查其变化情况 - jQuery: Record element changes in Array and check how it was by its index 如果每个值有多个,我如何根据其值从数组中仅删除一个元素 - How do I remove just one element from my array based on its value if there are more than one of each value 如何通过其$ index值获取ng-repeat中的元素 - How to get an element within an ng-repeat by its $index value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM