Home  >  Q&A  >  body text

javascript - console.log(["2","3"].push("1")) Why is the result 3

javascript

伊谢尔伦伊谢尔伦2711 days ago766

reply all(5)I'll reply

  • 世界只因有你

    世界只因有你2017-05-19 10:44:23

    push() 方法可向数组的末尾添加一个或多个元素,并返回新的长度。

    3 is actually the length of the new array.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-19 10:44:23

    Experiment yourself, push execution will return the length of the array

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:44:23

    What is printed is push的返回值,pushreturning the new length

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-19 10:44:23

    push() adds one or more elements to the end of the array and returns the new length.

    Reference http://www.w3school.com.cn/js...

    reply
    0
  • 高洛峰

    高洛峰2017-05-19 10:44:23

    The

    push() method adds one or more elements to the end of the array and returns the new length of the array, so what is printed is the length of the array.

    Refer to this document

    reply
    0
  • Cancelreply