Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. x = [{"id":"item1","val":"Items"},{"id":"item1","val":"Items"},{"id":"item1","val":"Items"}]
  2.  
  3. var clickId = // could be "item1", "item2"....
  4. var found = $.inArray(clickId, x); //
  5. if(found >=0)
  6. {
  7. x.splice(found,1);
  8. }
  9. else{
  10. x.push(new Item(clickId, obj)); //push json object
  11. }
  12.  
  13. x = [
  14. {"id":"item1","val":"Items"},
  15. {"id":"item1","val":"Items"},
  16. {"id":"item2","val":"Items"}
  17. ];
  18.  
  19. var clickId = [];
  20. var list = JSON.parse(x);
  21. $.each(list, function(index, value){
  22. if(clickId.indexOf(value.id) === -1){
  23. clickId.push(value.id);
  24. }
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement