Underscore.JS – intersection方法 语法 _.intersection(*arrays)JavaScriptCopy intersection方法返回传入数组的交集,即来自每个数组的共同值的数组。 示例 var _ = require('underscore'); var list1 = [1, 2, 3, 4, 5, 6] var list2 = [1, 2, 3, 7] var list3 = [1, 2, 4, 5, 6, 7, 8] //Example 1: intersection of list1 and list2 result = _.intersection(list1, list2); console.log(result) //Example 2: intersection of list1, list2, list3 result = _.intersection(list1, list2, list3); console.log(result)JavaScriptCopy 将上述程序保存为 tester.js 运行以下命令来执行该程序。 命令 >node tester.jsJavaScriptCopy 输出 [ 1, 2, 3 ] [ 1, 2 ]JavaScriptCopy