我在 javascript 中有以下对象:
var users = [{
'user': 'barney',
'age': 36,
'active': true
}, {
'user': 'fred',
'age': 40,
'active': false
}, {
'user': 'pebbles',
'age': 1,
'active': true
}];
我想从上面的对象中获取一个新对象,但像下面这样删除 active
键:
var users = [{
'user': 'barney',
'age': 36,
}, {
'user': 'fred',
'age': 40,
}, {
'user': 'pebbles',
'age': 1,
}];
我知道我可以通过 for 循环创建对象,但我正在寻找更好的方法来做到这一点。是否一行lodash代码就可以搞定?
最佳答案
如果你能使用最新的 JavaScript 特性...
users = users.map(({ active, ...rest }) => rest);
关于javascript - 如何使用 lodash 从数组中获取多个键值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42016092/