Further List Operations

Let's explore more features of the list data structure!

Appending a List

A list can be appended to another list using the spread operator. Here’s how it works:

Press + to interact
let myList = [5, 6, 7, 8];
Js.log([1, 2, 3, 4, ...myList]);

Console: [1,[2,[3,[4,[5,[6,[7,[8,0]]]]]]]]

However, the code below would not create the correct structure:

Press + to interact
let list1 = [1, 2, 3, 4];
let list2 = [5, 6, 7, 8];
Js.log([list1, ...[list2]]);

Output: ...

Get hands-on with 1400+ tech skills courses.