javascript - Is an array.forEach with a splice the best way to remove an entry from an array of unique Ids? -
i have array of objects. each object has unique usertestrid. here code using when want delete 1 of objects. efficient way can perform delete? concerned 1 time row has been deleted code still go way through array though there no chance of entry:
var id = 99; self.tests.foreach(function (elem, index) { if (elem['usertestid'] === id) self.tests.splice(index, 1); }); } var id = 99; self.tests.some(function (elem, index) { if (elem['usertestid'] === id) self.tests.splice(index, 1); homecoming true; }); homecoming false; }
could utilise array.some? stops looping 1 time homecoming true callback.
javascript
No comments:
Post a Comment