I\'m bashing my head against an error I can\'t work out how to fix. I have the following;
JSON
{\"products\":
[
{
\"product_id\" : \"123
If you want to map an object you can use Lodash. Just make sure it's installed via NPM or Yarn and import it.
With Lodash:
Lodash provides a function _.mapValues
to map the values and preserve the keys.
_.mapValues({ one: 1, two: 2, three: 3 }, function (v) { return v * 3; });
// => { one: 3, two: 6, three: 9 }
You can always do the following:
const SomeCall = request.get(res => {
const Store = [];
Store.push(res.data);
Store.forEach(item => { DoSomethingNeat
});
});
Objects, {}
in JavaScript does not have the method .map()
. It's only for Arrays, []
.
So in order for your code to work change data.map()
to data.products.map()
since products
is an array which you can iterate upon.