TS-Scribe - v0.6.2
    Preparing search index...

    Function toArray

    • Coerce a given value to an array.

      The function checks if the input value is an array-like or iterable object (like a string, Set, or Map). If so, it returns the value as an array. If the value is not iterable, it returns an array containing the value.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to convert into an array.

      Returns (T extends ArrayLike<TElement> | Iterable<TElement, any, any> ? TElement : T)[]

      An array containing the elements of the iterable if the value is iterable, or the value itself if it's not iterable.

      const arr1 = toArray([1, 2, 3]);
      console.log(arr1); // [1, 2, 3]

      const arr2 = toArray('hello');
      console.log(arr2); // ['h', 'e', 'l', 'l', 'o']

      const arr3 = toArray(42);
      console.log(arr3); // [42]