@corefunc/corefunc
    Preparing search index...

    Function arrayIsList

    • Type Parameters

      • T

      Parameters

      • arraySupposedToBeList: T[]

        The array being evaluated.

      Returns boolean

      • Returns true if array is a list, false otherwise.

      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.3.17

      console.log(arrayIsList([])); // ➜ true
      
      console.log(arrayIsList(["🍌", "🍏", "🍇", "🍊"])); // ➜ true
      
      console.log(arrayIsList(new Int16Array())); // ➜ false
      
      const list = ["🍌", "🍏", "🍇", "🍊"];
      list[-1] = "🍓";
      console.log(list); // [ '🍌', '🍏', '🍇', '🍊', '-1': '🍓' ]
      console.log(list.length); // 4
      console.log(Object.keys(list)); // [ '0', '1', '2', '3', '-1' ]
      console.log(arrayIsList(list)); // false