如何在javascript中验证没有循环的哈希表中包含的值? 例如:
var a = new Object(); // or just []
a[0] = 0
a['one'] = 1;
a['two'] = 2;
a['three'] = 3;
答案 0 :(得分:4)
您可以使用hasOwnProperty
var hash = new Object(); // or just {}
hash['one'] = 1;
hash['two'] = 2;
hash['three'] = 3;
if (hash.hasOwnProperty(k)) {
alert('Has')
}
答案 1 :(得分:0)
尝试jQuery
$(hashtablename).each(function (item) {
//code to verify.
});
虽然在内部它仍然会使用循环..