+ 6
[SOLVED] Can we remove or delete an element of an array? If the answer is yes, then, how?
3 Antworten
+ 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]
+ 4
no probs :]
marked the post with [SOLVED] so others can benefit from it in the future
+ 2
It works! I created a function for deleting elements of any array. Thank you, Burey!