国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaScript traverse object properties and methods

Syntax:
for(valueName in ObjectName){
// Code
}

Among them, valueName is the variable name, which holds the name of the attribute or method. Each Each cycle, the value of valueName will change.

Traverse the zhangsan object:

var zhangsan={}
zhangsan.name = "張三";
zhangsan.sex = "男";
zhangsan.say = function(){
        return "嗨!大家好,我來(lái)了。";
    }
zhangsan.contact = {
    tel : "029-81895644",
    qq : "1370753465",
    email : "itxueyuan@gmail.com"
}
var strTem="";  // 臨時(shí)變量
for(value in zhangsan){
   strTem+=value+':'+zhangsan[value]+"\n";
}
alert(strTem);

Given any string, use the for in statement to count the number of characters appearing:

function charNum(str){
    var charObj={}
    for(i=0,len=str.length;i<len;i++){
        if(charObj[str[i]]){
            charObj[str[i]]++;
        }else{
            charObj[str[i]]=1;
        }
    }
    var strTem="";  // 臨時(shí)變量
    for(value in charObj){
        strTem+='"'+value+'"的個(gè)數(shù):'+charObj[value]+'\n';
    }
    return strTem;
}
charNum("http://www.it.org");
charNum("134775444637722991919");


Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>無(wú)標(biāo)題文檔</title> <script>var zhangsan={} zhangsan.name = "張三"; zhangsan.sex = "男"; zhangsan.say = function(){ return "嗨!大家好,我來(lái)了。"; } zhangsan.contact = { tel : "029-81895644", qq : "1370753465", email : "itxueyuan@gmail.com" } var strTem=""; // 臨時(shí)變量 for(value in zhangsan){ strTem+=value+':'+zhangsan[value]+"\n"; } alert(strTem);</script> </head> <body> </body> </html>
submitReset Code