如何将数组中的对象值复制到javascript/lodash中的另一个空数组?
我有以下数组如何将数组中的对象值复制到javascript/lodash中的另一个空数组?,javascript,node.js,lodash,Javascript,Node.js,Lodash,我有以下数组 var-users=[{{u-id:“qwertyuiop”},{{u-id:“asdfghj1kl”},{u-id:“zxcvbnm123”}] 我的预期结果是[“qwertyuiop”、“asdfghj1kl”、“zxcvbnm123”] 除了使用foreach和push-to-array,我想知道是否还有其他方法可以得到这个结果 提前感谢。您可以在lodash中使用 var users = [{_id : "qwertyuiop"}, {_id: "asdfghj1kl"},
var-users=[{{u-id:“qwertyuiop”},{{u-id:“asdfghj1kl”},{u-id:“zxcvbnm123”}]代码>
我的预期结果是[“qwertyuiop”、“asdfghj1kl”、“zxcvbnm123”]代码>
除了使用foreach和push-to-array,我想知道是否还有其他方法可以得到这个结果
提前感谢。您可以在lodash中使用
var users = [{_id : "qwertyuiop"}, {_id: "asdfghj1kl"}, {_id : "zxcvbnm123"}];
_.pluck(users, '_id'); // → ["qwertyuiop", "asdfghj1kl", "zxcvbnm123"]
var-users=[{{u-id:“qwertyuiop”},{{u-id:“asdfghj1kl”},{u-id:“zxcvbnm123”}];
console.log(u.pull(用户,id'));//→ [“qwertyuiop”、“asdfghj1kl”、“zxcvbnm123”]
这是vanilla javascript最好解决的问题之一(除非您正在链接)
干杯
users.map(({_id}) => _id) // destructuring w/ arrow fnc
---
users.map(x => x._id) // arrow fnc
---
users.map(function(x) { return x._id} ) // es5