You need to use a recursion here, if you the property is "rest". In addition to get the value use list[property]:

function list_to_array(list) {
  const arr = [];
  
  for (const property in list) {
    if (property == "value") {
      arr.push(list[property]);
    } else if (property == "rest") {
      arr.push(...list_to_array(list[property])); // call list_to_array on the rest
    }
  }
  
  return arr; // return the arr
}

const list = {"value":10,"rest":{"value":20,"rest":null}};

const result = list_to_array(list);

console.log(JSON.stringify(result));

However, you can shorten the recursion - always add the value. If rest exists, return the call of the function with rest and the current arr. If no rest, return arr:

function list_to_array({ value, rest } = {}, arr = []) {
  arr.push(value);
  return rest ? list_to_array(rest, arr) : arr;
}

const list = {"value":10,"rest":{"value":20,"rest":null}};

const result = list_to_array(list);

console.log(JSON.stringify(result));

A simpler solution would be to use a while loop, and take the rest property value on each iteration:

function list_to_array(list) {
  const arr = [];
  let current = list;
  
  do {
    arr.push(current?.value);
  } while(current = current?.rest);
  
  return arr; // return the arr
}

const list = {"value":10,"rest":{"value":20,"rest":null}};

const result = list_to_array(list);

console.log(JSON.stringify(result));

Answer from Ori Drori on Stack Overflow
🌐
ArrayText
arraytext.com
Convert your text list to array online | Text to array converter
Convert your text list into an array online using ArrayText. Supports formatting for JavaScript, JSON, Python, PHP, Java, C#, Go, Ruby, Rust, SQL, and more.
🌐
Freetoolscorner
freetoolscorner.com › home › list tools › list to javascript array syntax
List to JavaScript Array Converter - Format JS Array Online - 2026
June 16, 2026 - Convert plain text lists into JavaScript array literals instantly. Support single quotes, double quotes, and backticks (template literals) online.
🌐
Listtoarray
listtoarray.com
List to Array Online Converter: Convert your text list into array online
Use this online list to array converter tool to convert your lengthy text lists or numerical lists into arrays. You can convert your lists into arrays online for Javascript, PHP, PERL, C#, Python, Java or any other supported programs.
People also ask

What can I convert to an array?
Paste a list of items—one per line—and the tool converts it to a JSON array. You can choose different quote styles: double quotes, single quotes, or no quotes.
🌐
nextjson.com
nextjson.com › array
List to Array Converter Online - NextJSON
Can I remove duplicates from my list?
Yes! The tool can deduplicate your list, keeping only unique items. Useful when merging lists or cleaning up data.
🌐
nextjson.com
nextjson.com › array
List to Array Converter Online - NextJSON
Does this site store my data in the cloud?
No, this site does not store or share your data in the cloud. Your data remains private and is kept locally on your broswer.
🌐
nextjson.com
nextjson.com › array
List to Array Converter Online - NextJSON
Top answer
1 of 3
1

You need to use a recursion here, if you the property is "rest". In addition to get the value use list[property]:

function list_to_array(list) {
  const arr = [];
  
  for (const property in list) {
    if (property == "value") {
      arr.push(list[property]);
    } else if (property == "rest") {
      arr.push(...list_to_array(list[property])); // call list_to_array on the rest
    }
  }
  
  return arr; // return the arr
}

const list = {"value":10,"rest":{"value":20,"rest":null}};

const result = list_to_array(list);

console.log(JSON.stringify(result));

However, you can shorten the recursion - always add the value. If rest exists, return the call of the function with rest and the current arr. If no rest, return arr:

function list_to_array({ value, rest } = {}, arr = []) {
  arr.push(value);
  return rest ? list_to_array(rest, arr) : arr;
}

const list = {"value":10,"rest":{"value":20,"rest":null}};

const result = list_to_array(list);

console.log(JSON.stringify(result));

A simpler solution would be to use a while loop, and take the rest property value on each iteration:

function list_to_array(list) {
  const arr = [];
  let current = list;
  
  do {
    arr.push(current?.value);
  } while(current = current?.rest);
  
  return arr; // return the arr
}

const list = {"value":10,"rest":{"value":20,"rest":null}};

const result = list_to_array(list);

console.log(JSON.stringify(result));

2 of 3
1

I suggest to avoid recursion here since with big lists that could overflow the stack easily. A simple while loop would do the task:

function list_to_array(list) {
  const arr = [list.value];
  while(list = list.rest) arr.push(list.value);
  return arr;
}

const list = {"value":10,"rest":{"value":20,"rest":null}};

const result = list_to_array(list);

console.log(...result);

🌐
JSFiddle
jsfiddle.net › greenpioneer › e9fsc5wb
Convert List to Array - JSFiddle - React, Tailwind, and code Playground
All ads in the editor and listing pages are turned completely off. You get to try and use features (like the Palette Color Generator) months before everyone else. Sort and categorize your Fiddles into multiple collections. You can make as many Private Fiddles, and Private Collections as you wish! Debug your Fiddle with a minimal built-in JavaScript console.
🌐
OneCompiler
onecompiler.com › javascript › 3ybayzezb
Convert Normal List to JS-Array - JavaScript - OneCompiler
Below are couple of ways to use arrow function but it can be written in many other ways as well. ... const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] const squaresOfEvenNumbers = numbers .filter((ele) => ele % 2 == 0) .map((ele) => ele ** 2) console.log(squaresOfEvenNumbers) ...
🌐
arrayThis
arraythis.com
Online array converter; convert your text list to array | arrayThis
Instantly convert your text list to array using arrayThis online tool; valid arrays for JS, PHP, PERL, Python and much more.
🌐
Daily Dev Tips
daily-dev-tips.com › posts › learn-how-to-convert-a-list-into-an-array-in-javascript
Learn how to convert a list into an array in JavaScript
August 26, 2020 - Ok, on to the magic part, let’s convert our array input into an array. We start by adding defining our variables. const textarea = document.getElementById('textarea'); const array = document.getElementById('array'); Now we can add our input listener to the textarea element.
Find elsewhere
🌐
Nextjson
nextjson.com › array
List to Array Converter Online - NextJSON
Paste a list of items—one per line—and the tool converts it to a JSON array.
🌐
Matthewb
matthewb.id.au › csv › text-list-to-javascript-array.html
Convert a text list into a JavaScript array.
July 12, 2018 - Convert a list of values into JavaScript array. Copy in the text and click Get Results button.
Top answer
1 of 3
3

Take the array content as string like this in a variable:

var words = "greet campaign coffee care revise ridge pilot full prison wrestle account dictionary start giant fast monarch patrol bear motif detective trouser title act speaker pursuit penny appear ballet agreement welcome similar sensation strong fog limited implicit nursery neighborhood infinite refund double achievement ample socialist intensify nomination visit drag retiree mislead situation credit oil clarify conscience war sow suitcase fixture worth fuss remain moment frighten spider breathe install interactive allow deadly cabin restless service rise integrity artist short circuit perception listen arrangement patience creep landscape stain citizen microphone nose bullet view category reign horizon news social reliable passion stroll constitutional adult city";

and then, write

var wordsArray = words.split(' ');
console.log(wordsArray);

That's magic of JS

2 of 3
1

First thing I want to say is that your syntax is incorrect. If you are trying to express a string, please use the format - var a = "fox hen lol haha";

If you meant your variable words to be a string, and each word to be separated by a space, I have the solution to your problem.

var words = "bla bla bla your words here";
var arrayOfWords = []; // Create the array to store words
arrayOfWords = words.split(" ");

And it's done. The array arrayOfWords contains all the words from the string as individual array objects.

If you are still confused, please comment below.

🌐
JSFiddle
jsfiddle.net › Zexov › m5c7sx4a
Convert List to Array - JSFiddle - Code Playground
All ads in the editor and listing pages are turned completely off. You get to try and use features (like the Palette Color Generator) months before everyone else. Sort and categorize your Fiddles into multiple collections. You can make as many Private Fiddles, and Private Collections as you wish! Debug your Fiddle with a minimal built-in JavaScript console.
🌐
ListDiff
listdiff.com › learn › convert-list-to-javascript-array
How to Convert a List to a JavaScript Array | ListDiff
July 4, 2026 - Paste your list into the converter. One value per line. Select JS Array from the format dropdown. Pick your quote style. Single, double, or backtick - match whatever your codebase already uses. Turn on Number Detect if the list is numeric. Otherwise every value comes out as a quoted string. Copy the output and paste it into your file. ... JavaScript and TypeScript accept single quotes, double quotes, or backticks for string literals - unlike JSON, which requires double quotes.
🌐
Easy Code Tools
easycodetools.com › home › coding tools › text list to array [ ]
Text List To Array [ ] | Easy Code Tools
September 9, 2026 - instantly convert your text list to array; valid for JS, PHP, PERL, PYTHON (as list) and much more. An array is a data structure that stores a collection of elements, and it is commonly used in programming languages for data storage and manipulation.
🌐
YouTube
youtube.com › watch
Convert Linked List To Array, And Back With JavaScript! - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2025 Google LLC
Published: December 1, 2022
🌐
Cliptics
cliptics.com › text-to-array-converter-online
Text to Array Converter Online | Convert List to Array Free
Convert text lists to arrays in JavaScript, Python, PHP, Java, C#, SQL. Advanced preprocessing with real-time conversion for developers.
🌐
CodePen
codepen.io › rebelchris › pen › bGpqqRm
Learn how to convert a list into an array in JavaScript
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage. All packages are different, so refer to their docs for how they work.
🌐
npm
npmjs.com › package › list-to-array
list-to-array - npm
August 14, 2015 - Latest version: 1.1.0, last published: 11 years ago. Start using list-to-array in your project by running `npm i list-to-array`. There are 69 other projects in the npm registry using list-to-array.
      » npm install list-to-array
    
Published: Aug 14, 2015
Version: 1.1.0