All files / arr contains.js

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18                        12x 12x     2x  
/**
 * 确认对象是否在数组中
 * @method arr/contains
 * @param {Array} arr 要操作的数组
 * @param {*} item 要搜索的对象
 * @returns {Boolean} 如果对象在数组中,返回 true
 * @example
 * var $contains = require('@spore-ui/kit/packages/arr/$contains');
 * console.info($contains([1,2,3,4,5], 3)); // true
 */
 
function contains(arr, item) {
  var index = arr.indexOf(item);
  return index >= 0;
}
 
module.exports = contains;