Home  >  Article  >  Web Front-end  >  How to output string array in javascript

How to output string array in javascript

藏色散人
藏色散人Original
2021-06-26 10:22:482989browse

Javascript method of outputting string array: 1. Output through "for(var key in arr){...}"; 2. Through "for(var i=0;i

How to output string array in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn