首页 > 编程知识 正文

java删除map的键值对,js创建map集合

时间:2023-05-06 17:24:09 阅读:32631 作者:4255

创建功能图()//图集合

//在此定义数据结构

var struct=function (密钥,值) {

this.key=key;

this.value=value;

}

//这是额外的方法

var put=function (密钥,值) {

for(varI=0; i this.arr.length; I ) {

if(this.ARR[I].key===key ) {

this.arr[i].value=value;

返回;

}

}

this.arr [ this.arr.length ]=new struct (key,value );

}

//获取的方法

varget=function(key ) {

for(varI=0; i this.arr.length; I ) {

if(this.ARR[I].key===key ) {

return this.arr[i].value;

}

}

返回空值;

}

//这是根据自己的需要定义的方法

vargetindex=function(index ) {

if(this.ARR.Length-1=index ) {

return this.arr[index].key;

}

返回空值;

}

//删除方法

varremove=function(key ) {

var v;

for(varI=0; i this.arr.length; I ) {

v=this.arr.pop (;

if(v.key*1===key*1) {

继续;

}

this.ARR.unshift(v;

}

}

//获取存储数量

var size=function

return this.arr.length;

}

//判断是否为空

var isEmpty=function

return this.arr.length=0;

}

//清空

var toNull=function

this.arr=new Array (;

}

//发布服务

this.arr=new Array (;

this.get=get;

this.put=put;

this.toNull=toNull;

this.remove=remove;

this.getIndex=getIndex;

this.getValue=getValue;

this.size=size;

this.isEmpty=isEmpty;

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。