It is probably a simple solution, but I can not seem to get it working :/ I want to create a new "response" from results collected trough json/api call.
jsonResponse = [
{"_id":"1","desc":"test desc","title":"Title 1"},
{"_id":"2","title":"Title 2","desc":"desc 2"}
];
I need to create a new array from this that looks like this;
var newResponse = [
{ "heading" : "Title 1", "summary" : "test desc"},
{ "heading" : "Title 2", "summary" : "desc 2"}
];
Stripping _id and changing "key". How can I go about doing it?
The Array.prototype.map function works wonders:
var newResponse = jsonResponse.map(function(item){
return { heading : item.title, summary : item.desc };
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With