js控制结构–3

  • 887

php中 count---获取数组长度

js 中 arr.length 返回数组中元素数目

var obj = {name : 'lisi' , age : 29 , area : 'beijing'};

for (var k in obj) {

console.log(k + '~' + obj[k]);

var k in obj 遍历数组

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="布尔教育 http://www.itbool.com" />
</head>
    <body>
        <script>
        var arr = ['赵' ,'钱' , '孙' , '李' ];
        for (var i = 0 ; i < arr.length ; i++) {
            console.log(arr[i]);
        };
        var obj = {name : 'lisi' , age : 29 , area : 'beijing'};
        for (var k in obj) {
            console.log(k + '~' + obj[k]);
        };
 
        </script>
    </body>
</html>

js控制结构–3

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="布尔教育 http://www.itbool.com" />
</head>
    <body>
        <script>
        var arr = ['赵' ,'钱' , '孙' , '李' ];
        for (var i = 0 ; i < arr.length ; i++) {
            console.log(arr[i]);
        };
        var obj = {name : 'lisi' , age : 29 , area : 'beijing'};
        for (var k in obj) {
            console.log(k + '~' + obj['k']);
        };
 
        </script>
    </body>
</html>

 

weinxin
我的微信
这是我的微信扫一扫
开拓者博主
  • 本文由 发表于 2016年6月3日22:11:05
  • 转载请务必保留本文链接:https://www.150643.com/43.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: