jskatas.org Continuously Learn JavaScript. Your Way.

Array API: Array.of()

Array.of() creates an array with the given arguments as elements.

Array.of creates an array with the given arguments as elements

dont mix it up with Array(10), where the argument is the array length
const arr = Array(10); assert.deepEqual(arr, [10]);
puts all arguments into array elements
const arr = Array.of(); assert.deepEqual(arr, [1, 2]);
takes any kind and number of arguments
const starter = [1, 2]; const end = [3, '4']; const arr = Array.of(...starter, ...end); assert.deepEqual(arr, [[1, 2], 3, '4']);

Related Katas

Array API

Difficulty Level

TBD

First Published

27 April 2015

Stats

3 tests to solve