# includesWith
通过自定义函数,判断数组是否包含项。
import { includesWith, isEqual } from '@hui-pro/utils';
includesWith(array, item, fromIndex, comparator);
// or
includesWith(arr, item, comparator);
//example
includesWith([{ id: 1 }, { id: 1, info: 123 }, { id: 2 }], { id: 1 }, isEqual); // => true
includesWith([1, 2, 3, 4, 5], 1); // => true
includesWith([1, 2, 3, 4, 5], 1, 2); // => false
Array.includes([{ id: 1 }, { id: 1, info: 123 }, { id: 2 }], { id: 1 }); // => false
TIP
ES5 includes 查找的是引用类型,若想通过比较引用类型值查找,可结合 includesWith、isEqual 查找。
# API
参数 | 说明 | 类型 | 默认值 | 可选值 |
---|---|---|---|---|
array | 要查找的数组 | Array | - | - |
item | 要查找的项 | Unknown | - | - |
fromIndex | 查找起始索引 | Number | - | - |
comparator | 自定义比较函数 | Function | - | - |