javascript object property lookup

后端 未结 3 864
孤街浪徒
孤街浪徒 2021-01-16 05:10

Due to object in javascript is associative map (HashMap in other programming languages) does next code

for (var prop in object) {
    if (prop === someConc         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 05:29

    I guess for the first one you meant:

    if ('prop' in obj) {
      // ...
    }
    

    Then you can talk about speed differences and different behavior.

    Homework:

    var obj = { prop: undefined }; // a bit philosophical...
    

提交回复
热议问题