using find
by John Wick
JavaScript
/* var propertyNames = [
{
"id": "64c7cc0bbb946069e46a3695",
"name": "Property1"
},
{
"id": "64c7c07723b3b966cd7f5801",
"name": "Property1"
}
]
const matchedPropertyName = propertyNames.find(item => item.id === id);
if (matchedPropertyName) {
console.log(matchedPropertyName.name);
}
*/
var propertyNames = [
[
{
"id": "64c7cc0bbb946069e46a3695",
"name": "Property1"
}
],
[
{
"id": "64c7c07723b3b966cd7f5801",
"name": "Property2"
}
]
]
var id = "64c7cc0bbb946069e46a3695"
/* for (let i=0; i<propertyNames.length; i++) {
if (propertyNames[i][0].id === id) {
console.log(propertyNames[i][0].name)
}
} */
const matchedPropertyName = propertyNames.find(itemArray => itemArray[0].id === id);
if (matchedPropertyName) {
console.log(matchedPropertyName[0].name);
}