Skip to main content
JS Data Transformation Tool

JavaScript String to Array Converter

Master converting a string to an array in modern JS: test js string to array, convert string to array js, turn string into array js, javascript separate string, and javascript object to array.

28 chars
Resulting JavaScript Array 4 elements
Generated JavaScript Snippet (string to array javascript)
// JavaScript Code will appear here

Techniques for Javascript String to Array Conversion

When dealing with web APIs and form submissions, you often need to change string into array or js parse string data. Here are the 3 canonical patterns for javascript string to array conversion:

1. String.prototype.split()

The most common method for string toarray javascript when dealing with delimiters (commas, slashes, spaces):

const arr = str.split(',');

2. Spread Operator [...]

To turn string into array js character by character with full Unicode and emoji surrogate support:

const arr = [...str];

3. Array.from()

Converts any iterable string into an array, optionally passing a mapping transform function:

const arr = Array.from(str);

Converting JavaScript Object to Array

When consuming REST APIs, you often need to transform a javascript object to array to use map, filter, or reduce:

  • Object.entries(user): Returns [['id', 1], ['name', 'Alex']].
  • Object.keys(user): Returns ['id', 'name'].
  • Object.values(user): Returns [1, 'Alex'].