0

I've json which looks little complex array of json, I want to parse "1238630400000" and "16.10", like this I need all the values. I'm not getting how we can parse all these values.

This is the code I've tried but no luck:

for (var key in myJSON.Stocks) {
       alert(myJSON.Stocks[key].stockPrice);

  }

var myJSON = {
    "Stocks": {
        "stockPrice": [
            [1238630400000, 16.10],
            [1238716800000, 16.57],
            [1238976000000, 16.92],
            [1239062400000, 16.43],
            [1239148800000, 16.62],
            [1239235200000, 17.08],
            [1239580800000, 17.17],
            [1239667200000, 16.90],
            [1239753600000, 16.81],
            [1239840000000, 17.35],
            [1239926400000, 17.63],
            [1241049600000, 17.98]
        ]
    }
}

Can someone help how can i get all these values?

1
  • 1
    That is not JSON, it's an object. Commented Mar 31, 2016 at 23:09

2 Answers 2

2

You can get the values by doing a simple forEach on the stockPrice array

myJSON.Stocks.stockPrice.forEach(function(data) { console.log(data[0], data[1]); });
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks gabesoft! I want the output in comma separated formatted in singe lime like this 1238630400000, 16.10, 1238716800000, 16.57,1238976000000,16.92 How can i get like this. I tried this (data[0], ',', data[1], ',') but its not giving expected output
I got it. I created array and pushed all these values
0

Here is the simplest way:

var csv = myJSON.Stocks.stockPrice.map((o)=>o.join()).join();
console.log(csv);

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.