You are not console.log
ing the right thing.
use: console.log(obj.prices[i]);
Update:
To get access each individual value (i.e. Date, Price, etc.), use the following:
for(var i = 0; i < obj.prices.length; i++){
console.log('Date', obj.prices[i][0]);
console.log('Price', obj.prices[i][1]);
console.log('Amount', obj.prices[i][2]);
}
jsfiddle
Update 2:
It may be helpful to structure the prices
data as an array of objects instead of an array of arrays. You can do things, like sort by date, either way, but you may find that it is easier to reason able an array of objects while also making it less error prone.
["Jun 02 2015 01: +0",3.931,"27070"]
{
"date": "Jun 02 2015 01: +0",
"price": "3.931,
"amount": "27070"
}
Then you can sort based on date using a custom sorting function:
var sorted_prices = prices.sort(function(a, b){
a = new Date(a.date),
b = new Date(b.date);
return a - b;
});
updated jsfiddle
If you wanted to keep your structure as an array of arrays, you would just pass a different value into new Date
.
a = new Date(a[0]),
b = new Date(b[0]);
As a side note, when working with large data sets like these, regular expressions come in handy. If you don't already know regex, I converted your array of arrays to an array of objects with the following regex:
Find: \["(.*?)",(.*?),"(.*?)"\]
Replace: {"date": "$1", "price": $2, "amount": $3}
To learn more about regex, I recommend this course.
Update:
var prices = [
"May 27 2015": [
{
"price": 0.292,
"amount": 888
},
{
"price": 0.242,
"amount": 118
}
],
"May 28 2015": [
{
"price": 0.492,
"amount": 88228
},
{
"price": 0.142,
"amount": 1118
}
]
]