Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

React: Iterating through Array of Objects

$
0
0

This is the way FileObject is built and I need help in figuring out how to iterate and find a value based on the date provided.

    interface MyProps{      date: string;      cDataFileName?: string | undefined;      iDataFileName?: string | undefined;    }

And in dev tools it shows up like this..

 FileObject: Array(4)0: {date: "8/26/2020", cDataFileName: : "small_range_c-compressed.json", influenzaDataFileName: "mall_range_f-compressed.jso"}1: {date: "8-24-2020", cDataFileName: : "small_range_c-compressed.json", iDataFileName: : "mall_range_f-compressed.jso"}2: {date: "8-13-2020", cDataFileName: : "small_range_c-compressed.json", iDataFileName: : "mall_range_f-compressed.jso"}3: {date: "7-15-2020", cDataFileName: : "small_range_c-compressed.json", iDataFileName: : "mall_range_f-compressed.jso"}length: 4

What I need to be able to do is find if in FileObject data exists for a date of say "8/26/2020"

and get the cDataFileName and IDataFileName values for it.

const today = "8/26/2020";  console.log("testing" + FileObject [today as any]);  // Its coming as testingUndefined.  if (today in FileObject ) {    console.log("today" + today);  // Not even going there  }

Please help me figure out a best way to iterate through this array of objects to get based on the date "8/26/2020" provided.

-----------Update 1----------This is how I had values aded to FileObject.

const FileObject: MyProps[] = [];     FileObject.push({                date: file,                cDataFileName: MycovidFileName,                iDataFileName: MyinDataFileName,              });

Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>