I need to select multiple array elements that have the same value. Using array.find () returns only the first element that satisfies the query condition. The construction below shows only "Donald Trump" in console:
const data = [
{
"position": "president",
"name": "Donald Trump",
"language": "english"
},
{
"position": "president",
"name": "Vladimir Putin",
"language": "russian"
},
{
"position": "king",
"name": "Shutruk-Nahhunte",
"language": "elamite"
},
];
let result = data.find(elem => elem.position == "president");
console.log(result.name);
But I need to get all the values as an array, - something like this:
[
"Donald Trump",
"Vladimir Putin"
]
How to do it right, considering also that the real array is huge. Thanks for any help!