How to split a string at the first `/` (slash) and surround part of it in a “?

Using split()

Snippet :

var data =$('#date').text();
var arr = data.split("https://stackoverflow.com/");
$("#date").html("<span>"+arr[0] + "</span></br>" + arr[1]+"https://stackoverflow.com/"+arr[2]);	  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="date">23/05/2013</div>

Fiddle

When you split this string ---> 23/05/2013 on /

var myString = "23/05/2013";
var arr = myString.split("https://stackoverflow.com/");

you’ll get an array of size 3

arr[0] --> 23
arr[1] --> 05
arr[2] --> 2013

Leave a Comment