Skip to content

使用new map存取删数据

保存、删除数据方便,可以定义new map

vue
data() {
  return {
    messageSelectMap: new Map()
  }
}

存数据:

js
this.messageSelectMap.set(index, jiLuId)

备注

key值可以任意定义,这里用了index值

删数据:

js
this.messageSelectMap.set(index)

取数据:

js
const jiLuIdList = []
for (let i = 0; i < this.messageSelectMap.size; i++) {
  jiLuIdList.push(this.messageSelectMap.get(i))
}

备注

new map获取值的 需要用get方法 参数是key

备注

上面例子用get(i) 是因为key值是index

备注

new map的长度是.size

如有转载或 CV 的请标注本站原文地址