UNPKG

@enonic/js-utils

Version:
27 lines (26 loc) 614 B
// array/includes.ts function sameValueZero(x, y) { return x === y || typeof x === "number" && typeof y === "number" && isNaN(x) && isNaN(y); } function includes(array, searchElement, fromIndex = 0) { if (array == null) { throw new TypeError('"array" is null or not defined'); } const o = Object(array); const len = o.length >>> 0; if (len === 0) { return false; } const n = fromIndex | 0; let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); while (k < len) { if (sameValueZero(o[k], searchElement)) { return true; } k++; } return false; } export { includes };