2021年3月20日星期六

how to get a nested object javascript react typescript

im getting an object from my redux state

 let weatherState = useSelector((state: RootState) => state.weather)       console.log('state ', weatherState); // returns state as expected and shown    console.log('loading ', weatherState.loading); // returns false    console.log('myWeather ', weatherState.weather?.description); // returns undefined   

enter image description here

the nested weather is an array, i'm unable to get to that array by using weatherState.weather?[0].description i put 'weatherState.weather?[0].description' inside an if statement, and it fails to compile

enter image description here

vscode is auto filling the description

enter image description here

how do i get the items from the array,

https://stackoverflow.com/questions/66727893/how-to-get-a-nested-object-javascript-react-typescript March 21, 2021 at 08:54AM

没有评论:

发表评论