Home  >  Q&A  >  body text

为什么得出结果为3?

var b=[2,3,4];
b["age"]=34;
alert(b.length)


靠近你靠近你2763 days ago1057

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 01:09:55

    Why is the result 3? - PHP Chinese website Q&A - Why is the result 3? - PHP Chinese website Q&A

    Take a look around and learn.

    reply
    0
  • 怪我咯

    怪我咯2017-03-27 17:58:09

    第一 var b=[2,3,4]; b是数组对象,数组长度为3;

    第二 b["age"] = 34; 是给b对象添加的age属性,并不会为数组添加第四个元素,因此数组的值还为[2,3,4],所以长度仍为3


    reply
    0
  • Cancelreply