0👍
It’s giving error because in find it doesn’t find any single item its return noting and you are trying to access .value
.
// Error
//console.log(settings['adminIcons'].find(menuItem => menuItem.key == "env1").value)
<script>
const array1 = [5, 12, 8, 130, 44];
const settings = {
'adminIcons':[
{"key":"env",
"value":"value1"}
]
}
const found = array1.find(element => element > 10);
console.log(settings['adminIcons'].find(menuItem => menuItem.key == "env").value);
// Error
//console.log(settings['adminIcons'].find(menuItem => menuItem.key == "env1").value);
</script>
0👍
Basically, you are accessing the value of item where item is not available in your data model.
This code will give you a string and this is where your error came from
menuItem.key == item.name.toLowerCase()) // if item.name = 'Test' will become 'test'.
Now, the returned of it it is not already the item you are accessing in your loop originally, rather give you a result but in new data. That’s why when you are accessing it’s value it say’s that cannot read property value of undefined.
Source:stackexchange.com