这是FileObject的构建方式,我需要帮助来确定如何根据提供的日期进行迭代和查找值。
interface MyProps{
date: string;
cDataFileName?: string | undefined;
iDataFileName?: string | undefined;
}
在开发工具中,它显示如下。
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
我需要做的是查找FileObject数据中是否存在日期为“ 8/26/2020”的时间
并为其获取cDataFileName和IDataFileName值。
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
}
请帮助我找出一种最佳方法,以根据提供的日期“ 8/26/2020”来遍历此对象数组。
----------更新1 ---------- 这就是我将值赋给FileObject的方式。
const FileObject: MyProps[] = [];
FileObject.push({
date: file,
cDataFileName: MycovidFileName,
iDataFileName: MyinDataFileName,
});
答案 0 :(得分:0)
这与打字稿或反应无关...
只需FileObject.find(obj => obj.date === "8/26/2020");