Is there a hashmap library for JavaScript?

后端 未结 8 1726
抹茶落季
抹茶落季 2021-02-14 10:35

In JavaScript, all Objects act a bit like hashmaps. However, the keys to these hashmaps must be strings. If they\'re not, they\'re converted with toString(). Tha

8条回答
  •  一向
    一向 (楼主)
    2021-02-14 11:07

    the answer is to use two arrays, one for keys, one for values.

    var i = keys.indexOf(key)
    if (i == -1)
      {keys.push(key); values.push(value)}
    else
      {values[i] = value; }
    

提交回复
热议问题