The array being evaluated.
true
false
arrayIsList
Checks whether a given array is a list. An array is considered a list if its keys consist of consecutive numbers from 0 to array.length-1. This function works only on non-typed arrays. This function returns true on empty arrays.
0
array.length-1
0.3.17
console.log(arrayIsList([])); // ➜ true Copy
console.log(arrayIsList([])); // ➜ true
console.log(arrayIsList(["🍌", "🍏", "🍇", "🍊"])); // ➜ true Copy
console.log(arrayIsList(["🍌", "🍏", "🍇", "🍊"])); // ➜ true
console.log(arrayIsList(new Int16Array())); // ➜ false Copy
console.log(arrayIsList(new Int16Array())); // ➜ false
const list = ["🍌", "🍏", "🍇", "🍊"];list[-1] = "🍓";console.log(list); // [ '🍌', '🍏', '🍇', '🍊', '-1': '🍓' ]console.log(list.length); // 4console.log(Object.keys(list)); // [ '0', '1', '2', '3', '-1' ]console.log(arrayIsList(list)); // false Copy
const list = ["🍌", "🍏", "🍇", "🍊"];list[-1] = "🍓";console.log(list); // [ '🍌', '🍏', '🍇', '🍊', '-1': '🍓' ]console.log(list.length); // 4console.log(Object.keys(list)); // [ '0', '1', '2', '3', '-1' ]console.log(arrayIsList(list)); // false
The array being evaluated.