发布于 1年前
JS 检测是不是类数组或者是数组(里面用了是否是函数是否是isWindow的检测)
// 检测是否为数组或者类数组
const isArrayLike = function isArrayLike(obj) {
if (obj == null) return false;
if (!/^(object|function)$/i.test(typeof obj)) return false;
let length = !!obj && "length" in obj && obj.length,
type = toType(obj);
if (isFunction(obj) || isWindow(obj)) return false;
return type === "array" || length === 0 ||
typeof length === "number" && length > 0 && (length - 1) in obj;
};