js split string into array – JavaScript String split() Examples

js split string into array – Use the .split() function. When each an empty string as the separator, the simple JavaScript split() function will return an array with one element per text character.

js split string into array – JavaScript split string – String into substrings

let sentmsg = "How are you doing today?";
const quotes = sentmsg.split(" ");

Use the limit parameter:

const quotes = sentmsg.split(" ", 3);

Use a letter as a separator:

const quotes = sentmsg.split("o");

Omit the separator parameter:

const quotes = sentmsg.split();

Split string into array

sentmsg = prompt("Enter your Boy Friends")
entryArray = sentmsg.split("");

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

The split() Method in JavaScript

// Split using a space character
let quotes = message.split(' ');

// The array
console.log(quotes); // ["We", "are", "the", "Best", "dreams", "important", "Students"]


// Access each of the elements of the array.
console.log(quotes[0]); // "We"
console.log(quotes[1]); // "are"
console.log(quotes[2]); // "the"
console.log(quotes[3]); // "Best"
console.log(quotes[4]); // "dreams",
console.log(quotes[5]); // "important"
console.log(quotes[6]); // "Students"

I hope you get an idea about js split string into array.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment