<script type="text/javascript">
var scripts = new Array();
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
var str=scripts.join(" : ");
document.write(str);
//document.write(scripts.join(" <br> "));
</script>
The output of the above code is here
PHP : ASP : JavaScript : HTML
You have seen displaying elements of an array by looping through the array. Now we will see how to display elements of an array by using join method. Join() method is a built in method in JavaScript which takes a delimiter and create a string by adding all elements of the array by placing the delimiter between them.
var str=scripts.join(" : ");
document.write(str);
How to create array by splitting a string using split() method
| nirmala | 04-10-2010 |
| i need to know how to get user input and store it in array and use array functions in it | |