Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

JavaScript Split String

by suresh

The JavaScript Split function is a String function, which is used to split the original string into an array of substring based on the separator we specified and returns them in an array. JavaScript Split string function accepts two arguments. The first argument is the separator you want to use, and the second integer value is used to restrict the output.

The JavaScript string Split function will not alter the original string. The basic syntax of the string Split function in JavaScript Programming Language is as shown below:

String_Object.split(Separator, limit)
  • String_Object: Please specify the valid string on which you want to perform Splitting.
  • Separator: Please specify the separator such as empty space, ‘,’ or ‘.’ you want to use. It can be string literal or JavaScript Regular Expression.
  • Limit: Please specify the integer number. This argument will restrict the number of elements written by the array.

If you ignore the first argument, the JavaScript Split function split each character and assigns them to an array. If you omit the second index, the JS string Split function starts from the beginning and continues till the end.

JavaScript Split Function Example

The following set of examples will help you understand the string Split function.

<!DOCTYPE html>
<html>
<head>
    <title> Split JavaScript </title>
</head>
<body>
    <h1> JavaScript Split Function </h1>
<script>
    var Str1 = "We are Abc working in abc company since abc years";
    var Str2 = Str1.split("");
    var Str3 = Str1.split(" ");
    var Str4 = Str1.split(" ", 4);
    var Str5 = Str1.split(/abc/i);
    var Str6 = Str1.split(/abc/i, 2);
 
    document.write(Str2 + "<br \>");
    document.write(Str3 + "<br \>");
    document.write(Str4 + "<br \>");
    document.write(Str5 + "<br \>");
    document.write(Str6 + "<br \>");
</script>
</body>
</html>

OUTPUT

JavaScript SPLIT Function

ANALYSIS

The following JS string split statement will split the original string into individual characters

var Str2 = Str1.split("");

Next, We used the empty space as a separator for the JavaScript Split string function. So, the following statement will split the original string into an array of words based on white space

var Str3 = Str1.split(" ");

We used the second argument to restrict the JavaScript array output to four.

var Str4 = Str1.split(" ", 4);

Next, we used substring “abc” as a separator for the Js Split String Function. Here i is the regular expression to perform case insensitive search

var Str5 = Str1.split(/abc/i);

Placed Under: JavaScript

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy