I have the following object:
const movies = {
1: {
id: 1,
name: 'Planet Earth',
},
2: {
id: 2,
name: 'Selma',
},
3: {
id: 3,
name: 'Million Dollar Baby',
},
4: {
id: 4,
name: 'Forrest Gump',
},
5: {
id: 5,
name: 'Get Out',
},
};
Then I want an array with only the property id. To do so I've tried something like:
const moviesArray = Object.values(movies);
const idArray = moviesArray.map(movie => Object.values(movie)[0]);
console.log(idArray);
It prints idArray properly but my question is if am I missing a method to solve this problem.
Object.values(movies).map(movie => movie.id)