This article describes two ways to output JavaScript arrays. Share it for your reference. The details are as follows:
Iterate through javascript arrays in two ways:
The first type:
Copy the code as follows:<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 (mainly using this method):
Copy the code as follows:<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>
I hope this article will be helpful to everyone's JavaScript programming.