I have array of objects that looks like this
var array=[
{id:123, value:"value1", name:"Name1"},
{id:124, value:"value2", name:"Name1"},
{id:125, value:"value3", name:"Name2"}
{id:126, value:"value4", name:"Name2"}
...
]
As you can see some names are repeated. I want to get new array with names only, but if some name repeats don't want to add it again, I want this array
var newArray = ["Name1", "Name2"]
I'm trying to this with map
var newArray = array.map((a)=>{
return a.name;
});
but the problem is that this returns
newArray = ["Name1", "Name1", "Name2", "Name2"]
How can I set some condition inside map, so it won't return element that already exist? I want to do this with maps or some other ES5 or ES6 feature.
Set? developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… – ppasler 13 hours ago