I am developing a web application and I use jQuery 1.5 and JavaScript for the main functionality of the app. I connect from my app to a RESTful interface where I GET information for a person. I use this function to retrieve the information from the json page:
var jqxhr = $.getJSON("example.json", function() { // store the data in a table }
My data in json format are like but I will get as a result more than one persons having the format of:
[{"person":{"time":"2010-02-18T17:59:44","id":1,"name": "John","age":60, "updated_at":"010-02-18T17:59:44"}}]
How can I store only the id, the name and the age of the person in a JavaScript table (to be more precise an array) and ignore the rest of the information?
You can use jQuery's
map
function:map
basically converts each item in anArray
, producing a newArray
with the modified objects.what do exactly mean by a javascript table u can store in a html table by
Here is the specific JavaScript / jQuery you need, based on the MAP function.
Here is a full example that will convert and display the results in HTML.