Home > Article > Web Front-end > How to output string array in javascript
Javascript method of outputting string array: 1. Output through "for(var key in arr){...}"; 2. Through "for(var i=0;i
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to output string array in javascript?
In JavaScript, you can traverse the array through a loop, and use the document.writeln(arr) method to output the array in the loop.
Traverse javascript arrays in two ways:
The first one:
<script language="javascript" type="text/javascript"> var str = "how are you today"; var arr = str.split(" "); for(var key in arr){ document.writeln(arr[key]); } </script>
The second one (mainly using this method):
<script language="javascript" type="text/javascript"> var str = "how are you today"; var arr = str.split(" "); for(var i=0;i<arr.length;i++){ document.writeln(arr[i]); } </script>
【 Recommended: javascript advanced tutorial】
The above is the detailed content of How to output string array in javascript. For more information, please follow other related articles on the PHP Chinese website!