使用 underscore.js 从两个数组中查找 A - B [英] Finding A - B from two arrays using underscore.js
本文介绍了使用 underscore.js 从两个数组中查找 A - B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须从 javascript 中的数组中过滤掉某些元素,并为此考虑使用 underscore.js.因为我是新手,所以感谢一些帮助.请参考下面的代码,我必须找到 A \ B 并将结果分配给 C .underscore.js 是否有任何方便的方法来做到这一点?
I have to filter out certain elements from an array in javascript and thought of using underscore.js for this purpose. As I am new to it,some help is appreciated.Please refer the code below , I have to find A \ B and assign the result to C . Does underscore.js has any convinience method to do that ?
function testUnderScore(){
alert("underscore test");
var a = [84, 99, 91, 65, 87, 55, 72, 68, 95, 42];
var b = [ 87, 55, 72,42 ,13];
var c = [];
alert(c);
}
推荐答案
通过使用difference
方法:
var c = _.difference(a, b);
http://documentcloud.github.com/underscore/#difference
这篇关于使用 underscore.js 从两个数组中查找 A - B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文