+ 6

[SOLVED] Can we remove or delete an element of an array? If the answer is yes, then, how?

23rd Feb 2018, 7:59 PM
Vicente Alfaro
Vicente Alfaro - avatar
3 Respostas
+ 9
use splice var arr = [1,2,3,4,5,6,7]; if you want to remove 4 for example then just do arr.splice(3, 1); first parameter is the index, second parameter is how many elements from that index now, splice also returns an array of the removed values so if tou do this: var arr2 = arr.splice(3,1); arr2 will look like this: [3]
23rd Feb 2018, 8:03 PM
Burey
Burey - avatar
+ 4
no probs :] marked the post with [SOLVED] so others can benefit from it in the future
23rd Feb 2018, 8:51 PM
Burey
Burey - avatar
+ 2
It works! I created a function for deleting elements of any array. Thank you, Burey!
23rd Feb 2018, 8:51 PM
Vicente Alfaro
Vicente Alfaro - avatar