Skip to content

Instantly share code, notes, and snippets.

@z2015
Created July 13, 2016 09:51
Show Gist options
  • Save z2015/f36367266e2c0a2d508f568944c9a138 to your computer and use it in GitHub Desktop.
Save z2015/f36367266e2c0a2d508f568944c9a138 to your computer and use it in GitHub Desktop.
check if the array of objects have duplicate property values
var values = [
{ name: 'someName1' },
{ name: 'someName2' },
{ name: 'someName4' },
{ name: 'someName2' }
];
var valueArr = values.map(function(item){ return item.name });
var isDuplicate = valueArr.some(function(item, idx){
return valueArr.indexOf(item) != -1;
});
console.log(isDuplicate);
//http://stackoverflow.com/questions/30735465/how-can-i-check-if-the-array-of-objects-have-duplicate-property-values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment