Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // for browser using, this code requires javascript 1.7+
  2.  
  3. var arr = [
  4. { foo: 'bar', lorem: 'ipsum' },
  5. { foo: 'bar', lorem: 'ipsum' },
  6. { foo: 'bar', lorem: 'ipsum dolor sit amet' }
  7. ];
  8.  
  9. arr = arr.map(JSON.stringify).reverse() // convert to JSON string the array content, then reverse it (to check from end to begining)
  10. .filter(function(item, index, arr){ return arr.indexOf(item, index + 1) === -1; }) // check if there is any occurence of the item in whole array
  11. .reverse().map(JSON.parse) // revert it to original state
  12.  
  13. console.log(arr); // [ { foo: 'bar', lorem: 'ipsum' }, { foo: 'bar', lorem: 'ipsum dolor sit amet' } ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement