Master AI & Build your First Coding Portfolio with SkillReactor | Sign Up Now

Lesson 6 - Basic String Operations

6.4 Split

JavaScript's split() function enables you to split a string using a specific separator.

const myStr = "A, B, C, D";
const myArr = myStr.split(", ");
console.log(myArr);
console.log(myArr[0]);

Here, we split the myStr using the separator , .

Note that the split() function generates an array after splitting a string.