Server returns me such object, but i need only array ITEMS.
How can i get it?
I tried array['items'] but the result is undefiend
{
"items": [
{
..
},
{
..
},
{
..
}
],..
,..
}
Server returns me such object, but i need only array ITEMS.
How can i get it?
I tried array['items'] but the result is undefiend
{
"items": [
{
..
},
{
..
},
{
..
}
],..
,..
}
// JSON string returned from the server
var text = '{"items":[{"name":"itemX" ,"price":15},{"name":"itemY","price":25},{"name":"itemZ","price":20}]}';
// Convert the string returned from the server into a JavaScript object.
var object = JSON.parse(text);
// Accessing a specific property value of an item
console.log(object.items[0].name); //itemX
// Extract 'items' in to a separate array
var itemsArray = object.items;
console.log(itemsArray); //[itemObject, itemObject, itemObject]