I am trying to extract the data in an array, however, it seems I am not doing it right, but when i console log it, I can see all the data. I want to be able to extract only all the titles in the array. Kindly show me where I am getting it wrong.
const movies = [
{
title: 'Show stopper',
rate: 5,
runtime: 120,
information: 'Show stopper is available',
},
{
title: 'Drive through',
rate: 233,
runtime: 65,
information: 'Drive through is not available',
},
];
componentDidMount() {
this.getItemValues();
}
getItemValues = () => {
const { title, rate } = movies;
console.log(title, rate);
}
moviesvariable is an array with objects in it. Your destructuring declaration indicates that you want to get the values of the properties "title" and "rate", but the array has no such properties. The objects in the array do, but you'd have to iterate through the array and do something with each object individually.