How to extract values of a specific property from an array of objects into a new array?
Hello everyone! I just started learning JavaScript and came across this task. I have an array of objects, each object represents, say, a user with fields name, age, and email. I need to get an array that contains only the values of the name property from each object. That is, from this array:
const users = [\n { name: 'Anna', age: 25, email: 'anna@example.com' },\n { name: 'Ivan', age: 30, email: 'ivan@example.com' },\n { name: 'Maria', age: 22, email: 'maria@example.com' }\n];\nI want to get:
\n['Anna', 'Ivan', 'Maria']\nI tried doing this with a for loop, but it turns out cumbersome. I've heard there are more elegant ways in modern Ja
No answers yet.
Log in to leave an answer