08 October, 2010

How to remove al element from array using Javascript

Yesterday, I got into a problem of removing any element from any array in javascript. After some testing, found the solution, thats better for me at least. The following code uses combination of plain javascript and jquery to remove element from an array.
Here is the code.

var arr = ['1', '2', '3'];
var usrId = '2';
//remove an element
arr.splice($.inArray(usrId, arr), 1);

Done

No comments: