I\'m working with an array of JavaScript Objects as such:
var IssuesArray = [{\"ID\" : \"1\", \"Name\" : \"Issue1\"},
{\"ID\" : \"2\", \"
Simplify??
var IssuesArray = {
1: "Issue1",
2: "Issue2",
3: "Issue3"
};
var issue2 = IssuesArray[2];
Why a list of hashes when a single hash will do?
var spliceID = function(id, arr) {
$(arr).each(function(i, el) {
if (el.ID == id) {
arr.splice(i,1);
return false;
}
});
return arr;
}
console.log(spliceID('2', IssuesArray));
Not sure if I understood your question correctly, but I would do:
$.each(IssuesArray, function(i, item){
if (item.ID == IDToBeRemoved) IssuesArray.splice(i, 1);
});
Without using jQuery or other frameworks:
var newArray = [];
var i=0, len=IssuesArray.length;
var bad_id = "2"; // or whatever
while(i<len) {
if(IssuesArray[i].ID !== bad_id) {
newArray.push(IssuesArray[i++]);
}
}
n
is your list item, so something like this should do the job:
$.grep(issuesArray, function(n) { return n.ID != "2"; })