JavaScript Object Literals & Array Literals

前端 未结 4 1264
忘了有多久
忘了有多久 2020-12-03 08:38

What is the difference between Object Literals and Array Literals in JavaScript? I know it has something to do with the length method but i don\'t fully understand it.

4条回答
  •  借酒劲吻你
    2020-12-03 08:50

    The difference is the way they're indexed.
    Objects have name, value pairs which are not ordered. In some browsers the order you added values will be the order you get when you traverse the object but not in all. The name is usually a string.
    Arrays are numerically indexed and the order is totally reliable

提交回复
热议问题