I have been stuck on this for a while. I have an array of object where the key is the same for all of the objects (see below). I am trying to extract the data from the first object in the array [0]. However when I console.log the data I get 'Cannot read property '0' of undefined. Here is the image of the data that I receive when I just filter the data.
And here is the code that I am using to get that data:
const handleClick = e => {
e.preventDefault();
const buttonValue = e.target.value;
console.log(buttonValue);
grid.on('rowClick', (...args) =>
args.filter(data => {
data.cells;
console.log(data.cells);
})
);
};
when I add an index of 0 to the console.log console.log(data.cells[0]);
I get the cannot read property 0 of undefined
I am not sure where data.cells
is coming from. Property 0 of undefined
clearly tells you that there is no such property as cells
on data
.
Also, I am not sure what exactly you mean by extracting objects , but I will be assuming that you need programmatic access to the objects.
First off, if you can see that the statement (8)[ n, n, n, n, n, n, n, n ]
tells you that it is an object with 8 objects of type n
.
Here is something I simulated in a console. So you can clear that up.
And to access it you need to use array indexing. Let's assume the name of the array is data
-
const firstElement = data[0]
You can also use loops and higher-order functions such as map()
, forEach()
too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.