Friday, February 17, 2012

how to use split() function in javascript

How to use Split() function in javascript String = Rajeev-Dhar-Dwivedi

<script>
function splitresult(){
var name = 'Rajeev-Dhar-Dwivedi' ;

var val=name.split("-");
alert(val[0]);
alert(val[1]);
alert(val[2]);

}
</script>
<b> String = Rajeev-Dhar-Dwivedi </b>
<input type="button" onclick="splitresult()" value="Call Slipt Function"  />

for example you have a string Rajeev-Dhar-Dwived and you want to cut string every - seprator them use split() function in javascript split() function is just like to explote() function in PHP
structer :
var arrayval=string.split("seprator"); 
 Example:
var str = 'Rajeev-Dhar-Dwivedi' ;
var val=name.split("-");
val[0]; // Rajeev
val[1]; // Dhar
val[2]; // Dwivedi

No comments:

Post a Comment

If you Satisfied , Please Leave a comment