turn strign into array code example

Example 1: 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);

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

Example 2: split a message js

const message = 'This is a test'

var args = message.split(' ');

console.log(args[0]) // Responds "This"
console.log(args[1]) // Responds "is"
console.log(args[2]) // Responds "a"
console.log(args[3]) // Responds "test"

Example 3: string to array javascript

const string = "Hello!";

console.log([...string]); // ["H", "e", "l", "l", "o", "!"]