Online Snippets Library

Split string using jquery

To Split string in jQuery we will use split() method.It splits a String object into an array of strings.The split() method returns the new array.

Syntax

string.split([separator[, limit]])

Example

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"> </script>
<title>Split string using jQuery</title>
</head>
<body>
<button id="count">Split Div</button>
<div id="splitData"></div>
</body>
</html>
Javascript
 $(document).ready(function(){
  $("#count").click(function(){
   var langName = 'Php-Ajax-JavaScript-Ajax';
   var langArray = langName.split('-',2);
  
  for(var i=0;i<langArray.length;i++){
        $('#splitData').append("<div>arr["+i+"] =>"+langArray[i]+"</div>");
    }
 });
});