js char array to string 1

js char array to string

const string = 'hi there';

const usingSplit = string.split('');              
const usingSpread = [...string];
const usingArrayFrom = Array.from(string);
const usingObjectAssign = Object.assign([], string);

// Result
// [ 'h', 'i', ' ', 't', 'h', 'e', 'r', 'e' ]

Here is what the above code is Doing:
1. We have a string called string.
2. We use the split() method to split the string into an array of characters.
3. We use the spread operator to split the string into an array of characters.
4. We use the Array.from() method to split the string into an array of characters.
5. We use the Object.assign() method to split the string into an array of characters.

Similar Posts