Hello,
i have the current .each in my javascript
var divs = array();
$('.div-item').each(function(){
var id = $(this).attr('id');
divs.push(id);
});
How would I delete an id from the array programmatically?
Hello,
i have the current .each in my javascript
var divs = array();
$('.div-item').each(function(){
var id = $(this).attr('id');
divs.push(id);
});
How would I delete an id from the array programmatically?
var list = [4,5,6];
list.splice(1, 1); // Remove one element, returns the removed ones.
list now equals [4,6]
function deleteId(divArray, id) {
var idx = $.inArray(id, divArray);
if(idx != -1)
divArray.splice(idx, 1);
}
EDITED: to use $.inArray: some versions of IE don't support the indexOf
method on arrays.
You can use jQuerys .map()
to create an array like this:
var divs = $('.div-item').map(function(i, e){
return this.id;
}).get();
To delete one entry, use Javascripts .splice()
:
divs.splice(3,1) // removes forth element
Syntax of .splice()
is startIndex, number of elements, new elements (optional)