In my reactjs library I'm using underscore.js right now see here, because the .map function doesn't work on a json object.
The data being passed using .map consists of this json schema, (here's an excerpt)
var json = {
"description": null,
"title": "Site Detail",
"ux-submit-text" : "submit form",
"href": "/api/v2/sites/{site_id}/",
"rel": "update",
"method": "PUT",
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "\n Your Site Name will appear in the title bar of the browser. It tells\n users and search engines what your site is about.\n ",
"title": "Site name"
}
}
}
};
I would like to use the built in .map function and not rely on an external library. What is wrong here?
Objects don't have a map function. You can iterate through an object like so:
var mapped = {};
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
var val = obj[key];
mapped[key] = ...;
}
It would help if react's map function converted it for you the way that underscore does it, because this way, it doesn't convert nested elements.
React doesn't provide a .map function; it's part of the JavaScript standard and is provided by the browser.
Ah, okay I thought that may have been the case. Would be useful though. Thanks for the info.
Most helpful comment
Objects don't have a
mapfunction. You can iterate through an object like so: