The for...in statement is used to traverse the properties of an array or object (loop over the properties of an array or object)

The for...in statement is used to loop over the properties of an array or object.

Each time the code in the for ... in loop executes, an operation is performed on an element of an array or a property of an object.

grammar:

for(变量 in 对象){
    execute code here
}

"Variable" is used to specify a variable. The specified variable can be an array element or a property of an object.

Example:

Use a for ... in loop to iterate through the array.

<html>
<body>

<script type="text/javascript">
var x
var mycars = new Array()
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"

for (x in mycars)
{
document.write(mycars[x] + "<br />")
}
</script>

</body>
</html>
 
 


Situations encountered in the project

        
        var mesTemp = {
                "Name" : { validateStatus: 'success' , errorMsg: null }, // institution name!!required!!
"UserName" : { validateStatus: 'success', errorMsg: null } , // 联系人 !!required!!
"Phone" : { validateStatus: 'success', errorMsg: null }, // 联系人电话(帐号) !!required!!
"Address" : { validateStatus: 'success', errorMsg: null }, // 详细地址 !!required!!
"UserCount" : { validateStatus: 'success', errorMsg: null }, // 用户数量 !!required!!
"ResourceAddress" : { validateStatus: 'error, errorMsg: "校本资源地址" }, // 校本资源地址(url) !!required!!
"Email" : { validateStatus: 'success', errorMsg: null }, // 邮箱
"District" : { validateStatus: 'success', errorMsg: null },
                        } ;
var index;
for( index in mesTemp){
if ( mesTemp[ index]. validateStatus == "error") {
message. error( mesTemp[ index]. errorMsg);
                return;
}
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324832322&siteId=291194637