Author -  Sai gowtham

How to split the strings in JavaScript

In this tutorial, we will learn about how to split the strings in javascript.

The split method helps us to split the string into an array of strings by using a separator where the exact place to split. it takes two arguments first one is a separator and the second one is limit.

Separator: We need to tell the split method at which point each split needs to occur in the string.

Limit: How many splits we need in the string.

const str = 'Hello javascript'
console.log(str.split())

If we don’t specify a separator argument it will simply return a whole string in the array.

string split method JavaScript

Using separator argument

const str = 'Hello javascript'
console.log(str.split(''))

split method

const str = 'javascript|is|a|high|level|programming|language'
console.log(str.split('|'))

split method JavaScript

Using limit argument

const str = 'javascript|is|a|high|level|programming|language'
console.log(str.split('|'),3)

split method limit argument JavaScript

Have you seen in the above image by using a limit argument it only split first 3 matches in the string?

Happy coding….

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY