JavaScript
// list of objects where the 'number' property is unique
var _numbers = [{number: 4589, name: "lorem"}, {number: 2554, name: "ipsum"}, {number: 9880, name: "siamet"}];
// find index for the object we want to remove from the list
var idx = -1;
var num = 9880;
for (var i = 0; i < _numbers.length; i++) {
if (num == _numbers[i].number) {
idx = i;
break;
}
}
// remove object from the list
if (idx != -1)
_numbers.splice(idx, 1);
No comments:
Post a Comment