React/JS How to get the value of last index of props.data which is an object
I have an application that passes array object to a child component and the child component can access the data via "props.data" whose format is as follows:
....
246: {key: 3510, date: "10/27/2020", name: "Canada", total_cases: 222887, cases_today: 2674, …}
247: {key: 3522, date: "10/28/2020", name: "Canada", total_cases: 225586, cases_today: 2699, …}
248: {key: 3540, date: "10/29/2020", name: "Canada", total_cases: 228542, cases_today: 2956, …}
249: {key: 3566, date: "10/30/2020", name: "Canada", total_cases: 231999, cases_today: 3457, …}
length: 250
__proto__: Array(0)
I want to get only the last value of total_cases and it shows an error that it's undefined when I tried "props.data[props.data.length-1].total_cases" Any idea what would cause this error? Thank you for your time!
from Recent Questions - Stack Overflow https://ift.tt/37VJdIZ
https://ift.tt/eA8V8J
Comments
Post a Comment