How can i get the second values (dates) in a javascript array?
I am new to this and i can't get it to work.
{"0":"11-28-2012","4":"11-29-2012","10":"12-03-2012"}
Thanks!
How can i get the second values (dates) in a javascript array?
I am new to this and i can't get it to work.
{"0":"11-28-2012","4":"11-29-2012","10":"12-03-2012"}
Thanks!
A very simple loop is below. You should check that the object hasOwnProperty which is important for more complicated objects.
If your object is called obj:
obj = {"0":"11-28-2012","4":"11-29-2012","10":"12-03-2012"};
for (var i in obj) {
console.log(obj[i]);
}
Or without the loop:
obj = {"0":"11-28-2012","4":"11-29-2012","10":"12-03-2012"};
console.log(obj[0]); // displays "11-28-2012"
Not really sure want do you want. But if you want to get date in month-date-year
use split()
.
var jsonDate = {"0":"11-28-2012","4":"11-29-2012","10":"12-03-2012"};
console.log(jsonDate["0"].split('-')[1]); //28
console.log(jsonDate["4"].split('-')[1]); //29
console.log(jsonDate["10"].split('-')[1]); //03