Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // creates an object only once - garbage be glad ^^
- let cachedObject = {};
- // array to be filtered
- let arr = [
- {id : 0, prop : 'blah'},
- {id : 1, prop : 'foo'},
- {id : 0, prop : 'bar'}
- ]
- // "filter" to object - keep original array - garbage be glad too ^^
- arr.map((item)=> cachedObject[item.id] = item)
- // optional, turns object to array
- arr = Object.values(cachedObject)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement