Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript object chain

/* 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}}
Comment

PREVIOUS NEXT
Code Example
Javascript :: is a letter javascript 
Javascript :: How to use body-parser package in using npm 
Javascript :: js capitalize word 
Javascript :: regex string case insensitive 
Javascript :: deserialize json jquery 
Javascript :: json vs gson 
Javascript :: change data js 
Javascript :: json limit express 
Javascript :: npm add latest version to package json 
Javascript :: datepicker jquery year range 
Javascript :: define function to get random value from array 
Javascript :: javascript destructure object and rename 
Javascript :: res.locals in express 
Javascript :: electron preload to renderer 
Javascript :: mdn foreach 
Javascript :: active js 
Javascript :: Repeat a String Repeat a String 
Javascript :: upload files to express using express-fileupload 
Javascript :: npm execute script with nodemon 
Javascript :: array_diff in jquery 
Javascript :: how to assign value to variable 
Javascript :: how to read xml element in xml2js 
Javascript :: jquery submit form 
Javascript :: change password firebase 
Javascript :: js array backwards 
Javascript :: Disable button if one of the checkboxes are not checked 
Javascript :: toastify 
Javascript :: javascript format date to dd-mm-yyyy 
Javascript :: react native share image 
Javascript :: wait for element to load javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =