How can I join an array of numbers into 1 concatenated number?

前端 未结 7 1599
梦谈多话
梦谈多话 2020-12-10 12:27

How do I join this array to give me expected output in as few steps as possible?

var x = [31,31,3,1]
//expected output: x = 313131;
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 12:37

    Your question asks for a number, most of the answers above are going to give you a string. You want something like this.

    const number = Number([31,31,3,1].join(""));

提交回复
热议问题