简体   繁体   中英

How to access JSON object element when the name of the element is a date?

I am developing a profit and loss tracker for an MMO, it uses the games API to get data about certain items in the games economy.

It returns this data as a JSON object, I am attempting to use this data to populate graphs in future. I'm struggling to access each element of the object. The data returned looks like so:

 daily: {2020-05-19T00:00:00.000Z: 794, 2020-05-20T00:00:00.000Z: 823, ... ETC

I need to access each element, then use its name and value to populate the graph, how would I go about doing this?

I need to access each element, then use its name and value to populate the graph

You can do that in many ways, such as:

for (let key of Object.Keys(yourObject)){
    let value = yourObject[key];
    //use both key and value as you please
}

If you need to access a specific property with a key like you have shown, you can do it with:

let value = yourObject["2020-05-19T00:00:00.000Z"];

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM