zoukankan      html  css  js  c++  java
  • 538 Object.values 、Object.entries、Object.getOwnPropertyDescriptors

    4.2.Object.values 和 Object.entries

    1. Object.values()方法返回一个给定对象的所有可枚举属性值的数组
    2. Object.entries()方法返回一个给定对象自身可遍历属性 [key,value] 的数组
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>ES8 对象方法扩展</title>
    </head>
    
    <body>
      <script>
        // 声明对象
        const school = {
          name: "哈哈哈",
          cities: ['北京', '上海', '深圳'],
          job: ['前端', 'Java', '大数据', '运维']
        };
    
        // 获取对象所有的键
        console.log(Object.keys(school));
        // 获取对象所有的值
        console.log(Object.values(school));
        // entries
        console.log(Object.entries(school));
        // 创建 Map
        const m = new Map(Object.entries(school));
        console.log(m.get('cities'));
      </script>
    </body>
    
    </html>
    

    4.3.Object.getOwnPropertyDescriptors

    该方法返回指定对象所有自身属性的描述对象

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>ES8 对象方法扩展</title>
    </head>
    
    <body>
      <script>
        // 声明对象
        const school = {
          name: "哈哈哈",
          cities: ['北京', '上海', '深圳'],
          job: ['前端', 'Java', '大数据', '运维']
        };
    
        // 对象属性的描述对象
        console.log(Object.getOwnPropertyDescriptors(school));
    
        const obj = Object.create(null, {
          name: {
            // 设置值
            value: '呵呵',
            // 属性特性
            writable: true,
            configurable: true,
            enumerable: true
          }
        });
        console.log(obj)
      </script>
    </body>
    
    </html>
    
  • 相关阅读:
    Mybatis JPA 插件简介(v2.1.0)
    linux-非root用户运行tomcat
    java版Web Socket,实现消息推送
    开源巨献:Google最热门60款开源项目
    java加密算法AES与RSA
    Jquery table元素操作-创建|数据填充|重置|隐藏行
    Mybatis JPA-集成方案+源码
    Mybatis JPA 插件简介
    eclipse maven构建
    初探JSP运行机制和与Servlet间的关系
  • 原文地址:https://www.cnblogs.com/jianjie/p/13680025.html
Copyright © 2011-2022 走看看