How to jQuery Split String to Array

How to jQuery Split String to Array

jQuery Split String to Array

If you need to break the rope to arrange the comma in the jQuery split string to array, then I will give you a solution to break the thread to arrange the comma, space etc. We will do it using jQuery split(). we will split the string separately with a space or a comma in the jQuery.

The split() function is used to separate a string from a string list, and then return a new list.

Read Also :  jQuery inArray() Function Example

I’ll give you a simple example of this booming example, I made a simple string with a comma. then i will use the split function to create more lists using the divider function in jQuery. so let’s look at a simple example:

Example : 1

<!DOCTYPE html>
<html>
<head>
   <title>How to jQuery Split String to Array - web-tuts.com</title>
</head>
<body>
<script type="text/javascript">
  var myString = "A,B,C,C,D,E,F,G,H";

  console.log(myString.split(','));
</script>
</body>
</html>

Example : 2

<!DOCTYPE html> 
<html>
 <head>
  <title>How to jQuery Split String to Array - web-tuts.com</title> 
</head>
<body>
<script>
  var name = 'Dharmik,Sanket,Fenil,Ved,Shlok';
  var nameArr = name.split(',');
  console.log(nameArr);

  // Accessing individual values
  alert(nameArr[0]); // Outputs: Dharmik
  alert(nameArr[1]); // Outputs: Sanket
  alert(nameArr[nameArr.length - 1]); // Outputs: Alice

  var str = 'Hello World!';
  var chars = str.split('');
  console.log();

</script>
</body>
</html>

I hope it can help you….

Read Also :  jQuery Set Attribute and Get Attribute