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):
2. Spread Operator [...]
To turn string into array js character by character with full Unicode and emoji surrogate support:
3. Array.from()
Converts any iterable string into an array, optionally passing a mapping transform function:
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'].