Is there an efficient way to remove a specific index from an array? (Javascript) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is there an efficient way to remove a specific index from an array? (Javascript)

For example, say I have the array: "Enemies" with a length of 75, and I want to remove index number 46. How would I remove this in an efficient way?

8th Jan 2017, 9:46 PM
Mini
3 Answers
+ 9
Splice it using splice () method. var arr = [0,1,2....your array] arr.splice(45,1) // remove element with index 45. 1 is number of items which will be removed. For example, if You want to remove elements with 45,46 index, call arr.splice(45,2)
8th Jan 2017, 10:34 PM
"IceQ" Sergej Kostenko
"IceQ" Sergej Kostenko - avatar
+ 4
var arr = […]; var arr2 = arr.join("!").replace(arr[46],"").split("!"); (tell me if it works…)
8th Jan 2017, 10:00 PM
Valen.H. ~
Valen.H. ~ - avatar
0
hey frnd wooh ur superb great.....hope I soon will be as much as u...
12th Jan 2017, 1:09 PM
Pranshu Ranjan
Pranshu Ranjan - avatar