by @CodingExample

How to split a string in JavaScript

Home » javascript » How to split a string in JavaScript

JavaScript has a built-in split() method by using that we can split a string into an array of substrings.

In this below example, we are splitting a string by the comma , separator.

const name = "code,examples";
const split = name.split(',');

// Now we can access the splitted strings like this

const firstName = split[0]; // code
const secondName= split[1]; // examples

Learn more about split method