模糊搜索和精确搜索的方法
搜索一般分为精确搜索和模糊搜索,搜索也叫过滤。
一种是模糊搜索,一般用过滤器来实现:
const a = [1, 2, 3, 4, 5]const result = a.filter((item) => {return item === 3})console.log('result', result)
但是,如果是精确搜索,则需要使用ES6中的find
const a = [1,2,3,4,5];const result = a.find(item =>{return item === 3})
浙公网安备 33010602011771号