_.contains(list, item, fromIndex, guard)
list集合包含指定的值则返回true,否则返回false
var result;
// 数组进行检索
result = _.contains([1, 2, 3], 2);
console.log(result) //=> true
// 对象进行检索
result = _.contains({x: 1, y: 2, z: 3}, 2);
console.log(result) //=> true
// 字符串进行检索
result = _.contains('123', "2");
console.log(result) //=> true
// arguments进行检索
function abc(){
result = _.contains(arguments, 2);
console.log(result); //=> true
}
abc(1, 2, 3);
var result;
// item为数字
result = _.contains(['1', 2, '3'], 2);
console.log(result) //=> true
// item为字符串
result = _.contains({x: '1', y: '2', z: '3' }, "4");
console.log(result) //=> false
// item为bool
result = _.contains([0, false], true);
console.log(result) //=> false
var result;
// item为数字
result = _.contains([1, 2, 3], 3, 0);
console.log(result) //=> true
// item为字符串
result = _.contains([1, 2, 3], 3, "3");
console.log(result) //=> true
// item为负值
result = _.contains({x: '1', y: '2', z: '3' }, "3", -1);
console.log(result) //=> true
result = _.contains({x: '1', y: '2', z: '3' }, "2", -1);
console.log(result) //=> false 由此可看出当fromIndex为负值的时候,fromIndex是根据list最后一位倒数
var result;
// guard为空,则根据fromIndex索引进行检索
result = _.contains(['a', 'b', 'c'], 'c', 2);
console.log(result) //=> true
// guard为true
result = _.contains(['a', 'b', 'c'], 'c', 3, true);
console.log(result) //=> true
// guard为false
result = _.contains(['a', 'b', 'c'], 'c', 3, false);
console.log(result) //=> false