I have this array:
aItems = [{
"PropertyA": "apple",
"PropertyB": "banana",
"PropertyC": "dog",
"PropertyD": "hotdog",
"PropertyE": "coldcat",
"PropertyF": "Y",
"PropertyG": "N"
},
...,
{
"PropertyA": "this",
"PropertyB": "is",
"PropertyC": "json",
"PropertyD": "code",
"PropertyE": "wow",
"PropertyF": "N",
"PropertyG": "N"
}]
I would like use lodash to obtain this result:
aItems = [{
"propertyA": "apple",
"propertyB": "banana",
"propertyC": "dog",
"propertyD": "hotdog",
"propertyE": "coldcat",
"propertyNEW": true,
"propertyG": false
},
...,
{
"propertyA": "this",
"propertyB": "is",
"propertyC": "json",
"propertyD": "code",
"propertyE": "wow",
"propertyNEW": false,
"propertyG": false
}]
I want map each property name with other names and change the value for some specific properties. Can I do it using lodash?
Create a mapping of old and new keys, like this
and also a mapping of old and new values, like this
And then using
_.map
and_.transform
, you can transform the object, like thisYes, since lodash v3.8.0 you can remap objects in any way desireable
ES5 code
ES2015/ES6 code