Skip to content

Instantly share code, notes, and snippets.

@6ui11em
Created April 20, 2018 07:18
Show Gist options
  • Save 6ui11em/f759b9ce6a465a683ea560e263c6683f to your computer and use it in GitHub Desktop.
Save 6ui11em/f759b9ce6a465a683ea560e263c6683f to your computer and use it in GitHub Desktop.
Javascript remove duplicates from array #javascript #array
var data = [
{
name: 'Kyle',
occupation: 'Fashion Designer'
},
{
name: 'Liza',
occupation: 'Web Developer'
},
{
name: 'Emily',
occupation: 'Web Designer'
},
{
name: 'Melissa',
occupation: 'Fashion Designer'
},
{
name: 'Tom',
occupation: 'Web Developer'
}
];
// Array Map
var jobs = data.map(function (item) {
return item.occupation;
});
// Logs ["Fashion Designer", "Web Developer", "Web Designer", "Fashion Designer", "Web Developer"]
console.log(jobs);
// Array Filter
var jobsUnique = jobs.filter(function(item, index){
return jobs.indexOf(item) >= index;
});
// Logs ["Fashion Designer", "Web Developer", "Web Designer"]
console.log(jobsUnique);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment