当前位置: 首页 > news >正文

javascript Map 和对象使用

先说结论,Map使用 for  of   对象使用for   in

const person ={

  name: '张三',

  age: 30,

  city: '北京'

};

const user = {

  id: 1,

  username: 'admin',

  isAdmin: true

};

const user = {

  id: 1,

  username: 'admin',

  isAdmin: true

};

User1获取id值

User1.get(“id”);

遍历

For(let[key,value] of user1){

  Console.log(`${key}:${value}`);

}

map用for of遍历,对象用for  in遍历

Const user1 = new Map(Object.entries(user);

const person = {

  name: '张三',

  age: 30,

  city: '北京'

};

console.log("Object.keys(person)",Object.keys(person)); console.log("Object.values(person)",Object.values(person))

for(let key in person){

                console.log("key",key);

                console.log(person[key]);

            }

for(let[key,value] of Object.entries(person)){
                console.log("aaaaaaaa",key,value)
            }

http://www.dtcms.com/a/175267.html

相关文章:

  • 安卓基础(点击按钮动态添加视图到容器)
  • 单片机-STM32部分:5、STM32CubeMX实现HAL点灯
  • Leetcode Hot 100字母异位词分词
  • Vue 项目中使用 EJS 模板动态注入环境变量
  • 哪些岗位需要考取城市客运安全员证?
  • SCINet 训练代码修改
  • cmake qt 项目编译(win)
  • npm下载插件无法更新package.json和package-lock.json文件的解决办法
  • clickhouse - 重新建表覆盖旧表-解决分区时间错误问题-197001
  • AI内容检测的技术优势与应用场景
  • Java注解
  • Linux开发工具【上】
  • win11共享打印机主机设置
  • 使用 Python 监控系统资源
  • LeetCode 解题思路 45(分割等和子集、最长有效括号)
  • 程序员学商务英语之Shipment Claim 运输和索赔
  • LeetCode 每日一题 2025/4/28-2025/5/4
  • Go语言——string、数组、切片以及map
  • 代码mark:脚本获取包含全角字符的字符串的长度
  • Grafana-新增用户
  • 【AI】如何自己训练AI大模型
  • 20250506| 物化视图学习
  • 【Python】--实现多进程
  • FastComposer论文问题与解决
  • 信息论06:信息增益——量化不确定性的艺术与科学
  • STM32H743单片机实现ADC+DMA多通道检测
  • 匿名函数对编译错误的影响
  • day17 天池新闻数据KMeans、DBSCAN 与层次聚类的对比
  • SpringSecurity配合Thymeleaf实现详解,以及实战用例
  • 【计网】ipconfig、ping、arp、tracert