Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将数组中的对象值复制到javascript/lodash中的另一个空数组?_Javascript_Node.js_Lodash - Fatal编程技术网

如何将数组中的对象值复制到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