开发者

The time-complexity of using object as a dictionary in JavaScript

开发者 https://www.devze.com 2023-03-22 02:22 出处:网络
I am considering using JavaScript object as a dicti开发者_开发问答onary. var dict = {} dict[\'a\'] = 1;

I am considering using JavaScript object as a dicti开发者_开发问答onary.

    var dict = {}
    dict['a'] = 1;
    dict['b'] = 2;

    var my_first = dict['a'];

I am not clear about the time-complexity of such implementation. Is it like hashing? Thank you.


JavaScript objects are often called "hashes" (mostly by recovering Perl addicts) or "hash tables" (unrepentant Java people). The typical look-up is somewhere between O(1) and O(log n).

0

精彩评论

暂无评论...
验证码 换一张
取 消