Get JSON stringify value

Antonio picture Antonio · Feb 17, 2017 · Viewed 41.3k times · Source

I have JSON stringify data like this :

[{"availability_id":"109465","date":"2017-02-21","price":"430000"},{"availability_id":"109466","date":"2017-02-22","price":"430000"},{"availability_id":"109467","date":"2017-02-23","price":"430000"}]

I want to get only price value of that data. I have tried this way but it doesn't work.

var stringify = JSON.stringify(values);

for(var i = 0; i < stringify.length; i++)
{
    alert(stringify[i]['price']);
}

How could I to do that ?

Answer

Yaman Jain picture Yaman Jain · Feb 17, 2017

This code will only fetch the price details.

var obj = '[{"availability_id":"109465","date":"2017-02-21","price":"430000"},{"availability_id":"109466","date":"2017-02-22","price":"430000"},{"availability_id":"109467","date":"2017-02-23","price":"430000"}]';
var stringify = JSON.parse(obj);
for (var i = 0; i < stringify.length; i++) {
    console.log(stringify[i]['price']);
}