How can I find items which have same name prop in the following array of objects with with ES6?
var pilots = [
{
id: 2,
name: "Wedge Antilles",
faction: "Rebels",
},
{
id: 8,
name: "Ciena Ree",
faction: "Empire",
},
{
id: 8,
name: "Ciena Ree",
faction: "Empire",
},
{
id: 40,
name: "Iden Versio",
faction: "Empire",
},
{
id: 66,
name: "Thane Kyrell",
faction: "Rebels",
}
];
var rebels = pilots.filter(function (item) {
return item.name === item.name;
});
console.log(rebels)
I tried this solution but it didn't work, it's returned all items.
return item.name === "Thane Kyrell";item.name === item.name? comparing the value with itself will always return true you will get all the values in output