Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取属性';长度';hashMap中未定义的_Javascript_Data Structures_Hashmap - Fatal编程技术网

Javascript 无法读取属性';长度';hashMap中未定义的

Javascript 无法读取属性';长度';hashMap中未定义的,javascript,data-structures,hashmap,Javascript,Data Structures,Hashmap,我正在尝试使用hashmap和 Cannot read property 'length' of undefined 这是我的密码 class HashMap{ table = new Array(17); get(key){ let idx = hashfun(key, this.table.length) return this.table[idx] } set(key, value){

我正在尝试使用hashmap和

Cannot read property 'length' of undefined
这是我的密码

class HashMap{
         table = new Array(17);
    
    
    get(key){
        let idx = hashfun(key, this.table.length)
        return this.table[idx]
    }

    set(key, value){
        let idx = hashfun(key, this.table.length)
        return this.table[idx]
    }
}

function hashfun(s, arrlen){
    console.log("***",s)
    let hash = 17;
    for(let i=0; i< s.length; i++){
        hash = (13 * hash * s.charCodeAt(i)) % arrlen;
    }
    return hash
}

let ht = new HashMap();
ht.set("trying")
ht.get()
类HashMap{
表=新阵列(17);
获取(键){
设idx=hashfun(key,this.table.length)
返回此.表[idx]
}
设置(键、值){
设idx=hashfun(key,this.table.length)
返回此.表[idx]
}
}
函数hashfun(s,arrlen){
console.log(“***”,s)
设hash=17;
for(设i=0;i

我正在尝试将键转换为Int,并将键分配给索引。如果我做错了什么,请告诉我。

您忘记将
传递给
get()
调用。(您的
set()
调用也没有
值)。