text to array javascript code example

Example 1: string to array javascript

const str = 'Hello!';

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

Example 2: javascript split string

// Split string into an array of strings
const path = "/usr/home/chucknorris"
let result = path.split("/")
console.log(result)
// result
// ["", "usr", "home", "chucknorris"]
let username = result[3]
console.log(username)
// username
// "chucknorris"

Example 3: convert a string to array in javascript

// Designed by shola for shola

str = 'How are you doing today?';
console.log(str.split(" "));

//try console.log(str.split(""));  with no space in the split function
//try console.log(str.split(","));  with a comma in the split function

Example 4: javascript text to array

var str = "How are you doing today?";
var res = str.split(" ");