There is no keyword foreach in js, but you can use var v in array to implement traversal. But it should be noted that
What I got was the key instead of the value. See example:
The code copy is as follows:
<script type="text/javascript">
// Normal array
var intArray = new Array();
intArray[0] = "first";
intArray[1] = "second";
for(var i = 0; i<intArray.length;i++)
{
alert(intArray[i]); // First, second
}
// What you get is the subscript (like the dictionary key)
for(var key in intArray)
{
alert(key); // 0,1
}
// Dictionary array
var dicArray = new Array();
dicArray["f"] = "first";
dicArray["s"] = "second";
// Unable to obtain
for(var i = 0; i<dicArray.length;i++)
{
alert(dicArray[i]);
}
// What you got is the subscript
for(var key in dicArray)
{
alert(key); // f,s
}
</script>