JS Built-ins
← Array30 / 226
ArrayArray.ofintermediate

Array.of() β€” mixed-type array

πŸ“– Usage Example
Array.of(1, 'two', true, null)
// β†’ [1, 'two', true, null]

Array.of() accepts values of any type and places them all in a new array.

Array.of() β€” heterogeneous elements

Array.of() works with any mix of value types. The resulting array's type is the union of its element types.

Challenge: Implement createMixed that takes a number, string, boolean, and null and returns them in an array using Array.of.

createMixed(1, 'two', true, null) // β†’ [1, 'two', true, null]
πŸ’‘ Hints (2)
  • β€’ `Array.of` accepts any types β€” just pass all four parameters directly.
  • β€’ TypeScript infers the union type automatically from the function signature.