Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting 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}];

Is there anyway to get me all the "text" property of this json_array in another array using Javascript/jQuery?

like:

var t_array = ["id","manifesto","also"....]
like image 976
Prasanna Avatar asked May 15 '26 20:05

Prasanna


1 Answers

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

var t_array = $.map(json_array, function(item) {
    return item.text;
});
like image 133
Frédéric Hamidi Avatar answered May 17 '26 10:05

Frédéric Hamidi