This article describes the usage of JS for...in traversal statements. Share it for your reference, as follows:
The for...in statement is used to loop through the properties of an array or object.
for (variable in object)
{
Execute the code here
}
The "variable" here is used to specify variables. The specified variable can be an array element or an object's attribute.
For example:
<!DOCTYPE html><meta charset="UTF-8"><script>var x;var zoon = new Array();zoon[0] = "cat";zoon[1] = "dog";zoon[2] = "pig";for (x in zoon){ console.log(zoon[x]);}var student={};student.name="Zhang San";student["age"]=20;for(var i in student)//The previous variable i is the object's attribute name { console.log(i);//name age console.log(student[i]);//Zhang San20}</script>The operation renderings are as follows:
For more information about JavaScript related content, please check out the topics of this site: "JavaScript Traversal Algorithm and Skills Summary", "JavaScript Switching Special Effects and Skills Summary", "JavaScript Search Algorithm Skills Summary", "JavaScript Animation Special Effects and Skills Summary", "JavaScript Errors and Debugging Skills Summary", "JavaScript Data Structures and Algorithm Skills Summary" and "JavaScript Mathematical Operation Usage Summary"
I hope this article will be helpful to everyone's JavaScript programming.