JS基础10-对象3枚举对象的属性

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,minimal-ui:ios">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="">
    <script src=""></script>
</head>

<body>

</body>
<script>
    /* 
    枚举属性:指将对象中的所有属性获取
    for-in 语句
    for(propName in Obj){
        语句...
    }
    注:如果属性名是用symbol()创建的符号,那么用for-in语句是无法枚举的
    */
    let obj = {
        name: 'zs',
        age: 10,
        gender: 'man'
    }
    for (key in obj) {
        console.log(key, obj[key])
    }
</script>

</html>

  

posted @ 2022-11-29 16:33  SadicZhou  阅读(10)  评论(0编辑  收藏  举报