如何使用下划线将数组或对象推入一个数组?

use*_*858 2 javascript underscore.js

我基本上在mongo中使用$ all运算符,我得到的输入可能是数组或单个元素,如下所示.那么如何使用下划线将所有元素放在一个数组中然后呢

userId = 'a';
userIds = ['a', 'b', 'c'];
otherId = ['a'] or 'a';
searchArray = [userId, userIds, otherId]
db.collections.find({userIds: {$all: searchArray}})
Run Code Online (Sandbox Code Playgroud)

Sus*_* -- 6

只要它们是数组,就可以使用union.

_.union(arrays) 

var userId = ['a'],
    userIds = ['a', 'b', 'c'];
    otherId = ['a'],

searchArray = _.union(userId, userIds, otherId);
Run Code Online (Sandbox Code Playgroud)