使用js设计一个函数has数组数据判断该数组中是否存在该数据返回值是布尔类型true代表存在false代表不存在
function has(arr, data) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === data) {
return true;
}
}
return false;
}
使用示例:
const arr = [1, 2, 3, 4, 5];
console.log(has(arr, 3)); // true
console.log(has(arr, 6)); // false
原文地址: https://www.cveoy.top/t/topic/0KH 著作权归作者所有。请勿转载和采集!