Remove Array Value By index in jquery
Your example code is wrong and will throw a SyntaxError. You seem to have confused the syntax of creating an object Object
with creating an Array
.
The correct syntax would be: var arr = [ "abc", "def", "ghi" ];
To remove an item from the array, based on its value, use the splice method:
arr.splice(arr.indexOf("def"), 1);
To remove it by index, just refer directly to it:
arr.splice(1, 1);
Use the splice method.
ArrayName.splice(indexValueOfArray,1);
This removes 1
item from the array starting at indexValueOfArray
.