Rantai objek JavaScript

/* List structure: a nested set of objects. NOT an array.
Each object holds reference to its successor in the object chain. */

// Build a list (object chain) using an array argument 
arrayToList = (array) => {
  let list = null;
  for (let i = array.length - 1; i >= 0; i--){
    list = {value: array[i], rest: list};
  }
  return list;
};

console.log(arrayToList(["foo", "bar"]));
// → {value: "foo", rest: {value: "bar", rest: null}}
Intra