Retrieving data from JsonArray using JS / jQuery

I have a JsonArray something like this.

var json_array = [{ "text": "id", "size": 4}, { "text": "manifesto", "size": 4}, { "text": "also", "size": 4}, { "text": "leasing", "size": 4}, { "text": "23", "size": 4}];

Anyway, to get all the "text" property of this json_array in another array using Javascript / jQuery?

as:

var t_array = ["id","manifesto","also"....]
+3
source share
4 answers

You can use $. map () to project the appropriate information from your existing array into a new one:

var t_array = $.map(json_array, function(item) {
    return item.text;
});
+9
source
var t_array = [];

for (var i=0; i< json_array.length; i++)
    t_array.push(json_array[i].text);
+2
source

I think you will need to build t_arraygoing throughjson_array

+1
source

sort of:

var t_array = [];
$.each(json_array,function(i,o) {
  t_array.push(o.text);
})

http://jsfiddle.net/bouillard/2c66t/

+1
source

All Articles