texas697
texas697

Reputation: 6387

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

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

Upvotes: 1

Views: 50

Answers (2)

Sze-Hung Daniel Tsui
Sze-Hung Daniel Tsui

Reputation: 2332

Check out the splice docs.

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

Upvotes: 2

antyrat
antyrat

Reputation: 27765

So just use splice method:

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

Upvotes: 3

Related Questions