js_对象的遍历与删除/for...in

<!--@description-->
<!--@author beyondx-->
<!--@date Created in 2022/07/31/ 10:51-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象的遍历及删除</title>
</head>
<body>
    <script>
        // var o1 = {
        //     name: '路飞',
        //     age: 15,
        //     sex: '男'
        // }
        //
        // // console.log(o1);
        // // for...in遍历对象
        // for(var index in o1) {
        //     console.log(o1[index]);
        // }

        // // for...in遍历数组
        // var arr = [2, 4, 7, 8, 4];
        // for(var index in arr) {
        //     console.log(arr[index]);
        // }

        // 对象的删除
        var person1 = {
            name: '张三',
            age: 15,
            sex: '男'
        }
        console.log(person1);

        delete person1.age;
        console.log(person1);

    </script>
</body>
</html>

posted on 2022-07-31 11:06  beyondx  阅读(281)  评论(0编辑  收藏  举报

导航