具有两个数组的underscore.js [英] underscore.js with two arrays

查看:66
本文介绍了具有两个数组的underscore.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数组:

['aaa', 'bbb', 'ccc', 'ddd']

我的目标是从中删除意外值:

My goal is to remove from it unexpected values:

我尝试使用下划线而没有来实现此功能,如下所示:

I tried to do it with underscore without function like below:

_.without(['aaa', 'bbb', 'ccc', 'ddd'], 'bbb', 'ccc');

它可以正常工作,但不幸的是,它不适用于数组:

It works fine, but unfortunately it does not work with array:

_.without(['aaa', 'bbb', 'ccc', 'ddd'], ['bbb', 'ccc']);

我用Google搜索了一下,然后找到了 underscore.js-是否有一个函数产生一个数组,该数组将两者之差

I've googled a bit and find the post underscore.js - Is there a function that produces an array thats the difference of two arrays?

但是在我的情况下,这个也不起作用,即返回如下内容:

But in my case this one also does not work, namely it returns somthing like that:

"a","a","a"

当我厌倦了使用apply函数时。

when I tired to use apply function.

有人可以建议需要采取什么措施来删除所有带有数组的意外键吗?

Can some one suggest what need to be done to remove all unexpected keys with array?

推荐答案

您是否尝试过 _ .difference

Have you tried _.difference?

_.difference(['aaa', 'bbb', 'ccc', 'ddd'], ['bbb', 'ccc']);

这篇关于具有两个数组的underscore.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆