0

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];
2
  • 1
    data.Header[0] + " " + data.Values[1][0]; Commented Aug 7, 2017 at 15:59
  • If you just want the first go with the upper approach. However there may be a better solution based on your usecase. Commented Aug 7, 2017 at 16:05

2 Answers 2

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];
Sign up to request clarification or add additional context in comments.

Comments

1
    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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.