how to use split() function in javascript
<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
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
Comments
Post a Comment
If you Satisfied , Please Leave a comment