简体   繁体   中英

JavaScript return object property value

I have this object:

{"Header":["Date","Test1","Test2","Test3","N/A","Test4","Test5"],
 "Values":[["Total Unique","79 280","1 598","5 972","20","2 633","9 696"],
           ["2017-06-19","28 026","1 036","3 667","20","1 097","4 672"]]}

My desired result is this:

Date
2017-06-19

What I was able to achieve:

Date ["2017-06-19","28 026","1 036","3 667","20","1 097","4 672"] 

Using this code:

vm.header = data.Header[0];
vm.data1 = data.Values[1];

Because data.Values is a two-dimensional array you can get the desired result by changing the code to:

vm.header = data.Header[0];
vm.data1 = data.Values[1][0];
    Header[0] = 'Date';
    Header[1]= 'Test1';
    Header[2]= 'Test2';
    Header[3]= 'Test3';
    Header[4]= 'N/A';
    Header[5]= 'Test4';
    Header[6]= 'Test5';
    Values is 2D array
    Values[0] = ["Total Unique","79 280","1 598","5 972","20","2 633","9 696"]
    Values[1]=["2017-06-19","28 026","1 036","3 667","20","1 097","4 672"]

What you have tried so far is data.Header[0] would give you 'Date'. data.Values[1] would give you whole array. So you need to get "2017-06-19" you have to get first element of that array ie data.Values[1][0]

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