How to output string array in javascript

藏色散人
Release: 2023-01-07 11:41:02
Original
3010 people have browsed it

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>
Copy after login

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>
Copy after login

【 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template