0

i have an array of object menuProduitSet[] , after pushing to it 'menuProduit' which is object of object how can in remove duplicate objects ???

var menuProduitSet = [];
 $('select').children('optgroup').children('option:selected').each(function () {
 var ch = $(this).parent().parent().parent().parent().attr('class').substring(4, 5);
 if (ch !== 'undefined') {
 if (ch !== 'c') {
 var produit = {"prodId": $(this).val()};
 var menuProduit = {menuProduitPK: {menu: menu["menuId"], produit: produit["prodId"], choix: ch}, menu: {menuId: menu["menuId"]}, produit: {prodId: produit["prodId"]}};
 menuProduitSet.push(menuProduit);
 }
 }
 });
asked Jan 31, 2017 at 11:58
2

1 Answer 1

1

I recommend if you can use Javascript libraries such as underscore or lodash, look at .uniq function. .uniq - Underscore.js - _.uniq - Lodash

So when you have the final array(menuProduitSet):

// by menu.menuId:
var byMenuId = _.uniq(menuProduitSet, function(m){ return m.menu.menuId; }); 
// by produit.prodId 
var byProdId = _.uniq(menuProduitSet, function(m){ return m.produit.prodId; }); 
answered Jan 31, 2017 at 12:38
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.