javascript中的HashMap对象 [英] HashMap objects in javascript
本文介绍了javascript中的HashMap对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
循环遍历JavaScript对象
获取对象数组键
有没有办法在javascript中使用hashmaps。我找到了这个页面,其中显示了一种方法javascript中的hashmaps。基于此我将数据存储如下:
Is there a way to use hashmaps in javascript. I found this page which shows one way of having hashmaps in javascript. Based on that I am storing the data as below:
var map = new Object();
map[myKey1] = myObj1;
map[myKey2] = myObj2;
function get(k) {
return map[k];
}
但我想要<$ c $的keySet(所有键) c> map 对象就像在Java中完成一样( map.keySet();
)。
But I want the keySet (all the keys) of the map
object just like it is done in Java (map.keySet();
).
任何人都可以告诉我如何获得此对象中的所有键?
Can anyone show me how can get all the keys present in this object?
推荐答案
for (var key in map) {
if (map.hasOwnProperty(key)) {
alert(key + " -> " + map[key]);
}
}
https://stackoverflow.com/a/684692/106261
实际上这种方式要好得多:
var keys = Object.keys(map);
这篇关于javascript中的HashMap对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文