I have below array how to get list of names where the age is greater than 18.
so the out put should be: ["Anna", "Bob"]
friends = [{
name: 'Anna',
books: ['Bible', 'Harry Potter'],
age: 21
}, {
name: 'Bob',
books: ['War and peace', 'Romeo and Juliet'],
age: 26
}, {
name: 'Alice',
books: ['The Lord of the Rings', 'The Shining'],
age: 18
}]
I have tried below
let names = friends.map((item) => {if (item.age > 18){ return item.name}});
but i got below output
["Anna", "Bob", undefined]