how to convert a string in array in javascript code example
Example 1: convert string to array js
let string = 'ABCDEFG';
let newArray = string.split('');
console.log(newArray);
Example 2: string to char array in javascript
const string = 'hi there';
const usingSplit = string.split('');
const usingSpread = [...string];
const usingArrayFrom = Array.from(string);
const usingObjectAssign = Object.assign([], string);
Example 3: javascript convert in a string the items of an array
const arr = [1, 2, 'a', '1a'];
const str = arr.toString();
console.log(str);
Example 4: convert a string to array in javascript
str = 'How are you doing today?';
console.log(str.split(" "));
Example 5: javascript turn string into array
var fruits = 'apple, orange, pear, banana, raspberry, peach';
var ar = fruits.split(', ');
console.log( ar );
Example 6: convert a string to array in javascript
let price = "shola";
console.log(Object.values(price));