如何将一组数字连接成 1 个串联数字? [英] How can I join an array of numbers into 1 concatenated number?

查看:24
本文介绍了如何将一组数字连接成 1 个串联数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何加入这个数组,以尽可能少的步骤给我预期的输出?

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;

推荐答案

使用数组 join 方法.Join 将数组的元素连接成字符串,并返回细绳.默认分隔符是逗号 (,).这里的分隔符应该是一个空字符串.

Use array join method.Join joins the elements of an array into a string, and returns the string. The default separator is comma (,). Here the separator should be an empty string.

var  x = [31,31,3,1].join("");

将结果作为数字

const  x = +[31,31,3,1].join("");

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

这篇关于如何将一组数字连接成 1 个串联数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆