空夜

js操作map——创建、赋值、删除、遍历
js遍历map仅遍历key: for (item in map) { console.log(ite...
扫描右侧二维码阅读全文
12
2019/03

js操作map——创建、赋值、删除、遍历

js遍历map

仅遍历key:

  for (item in map) {
      console.log(item)
  }

遍历key和value

for (item in map) {
    console.log(map[item])
}

js获取map的长度

获取map中key的数量:Object.keys(map).length

js中map的增删改查

构造和添加值:

var map = {};
map[key] = value;

查询:map[key]map.key

删除key

delete(map[key]) 
delete map[key]
Last modification:March 12th, 2019 at 01:33 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment