We have a String containing numbers separated by , or any other delimiters,and we want to get those numbers collected into an array.Here is the steps
gives 40 //3rd element
<script type="text/javascript">
var str="20,30,40";
var arr=new Array();
arr=str.split(",");
document.write(arr[2]);
</script>
var str="20,30,40";
var arr=new Array();
arr=str.split(",");
document.write(arr[2]);
</script>
gives 40 //3rd element
function check()
ReplyDelete{
var names="apple,ball,cat";
var arrnames=names.split(",");
alert(arrnames[0]+":"+arrnames[1]);
}
o/p:
apple:ball
here i neednt to create arrayobject explicity.
Thats correct,Its just to give the clarity to user that arr is Array() object..
ReplyDelete