我想在obj中重命名键:
objs = {
one: { description: "value", amount: 5, value: { description: "value desc", identifier: "some text"} },
two: { description: "value", amount: 5, value: { description: "value desc", identifier: "some text"} }
}
进入这个:
objs = {
one: { original_description: "value", amount: 5, value: { description: "value desc", identifier: "some text"} },
two: { original_description: "value", amount: 5, value: { description: "value desc", identifier: "some text"} }
}
答案 0 :(得分:7)
你真的不需要lodash。您需要做的是使用旧值在对象上创建一个新键,然后删除旧键。例如:
class Thing a <= SubThing a
act :: a -> Unit
如果您不熟悉Object.keys(objs).forEach(function (key) {
objs[key].original_description = objs[key].description;
delete objs[key].description;
});
运营商,请参阅the MDN documentation for delete