I have an array like:
var abc = ["a","b","c"];
And the indexes are 0,1,2
Suppose, I want to delete the 2nd item "b" and I the indexes swipe!
Out put:
abc = ["a","c"]
and the indexes are 0,1
How can I achieve this?
I have an array like:
var abc = ["a","b","c"];
And the indexes are 0,1,2
Suppose, I want to delete the 2nd item "b" and I the indexes swipe!
Out put:
abc = ["a","c"]
and the indexes are 0,1
How can I achieve this?
Use the splice function :
abc.splice(1,1) // from index 1, removes 1 element
Be careful that this changes the original array.
Use splice(). E.g:
abc.splice(1, 1);
would perform what you wanted in your example. abc[1] would now be "c".
You can use the array splice abc.splice(1,1);
Details: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice