如何在 JavaScript 中将整数数组转换为字符串数组?


要将整数数组转换成字符串数组,在 JavaScript 中使用 map(String)。假设以下为我们的整数数组 −

var integerValues = [101,50,70,90,110,90,94,68];

将整数数组转换成字符串数组 −

integerValues.map(String);

示例

以下是代码 −

var integerValues = [101,50,70,90,110,90,94,68];
console.log("The integer array value=");
console.log(integerValues);
integerValues.map(String);
console.log("The string array value=");
console.log(integerValues)

要运行以上程序,你需要使用以下命令 −

node fileName.js.

这里,我的文件名是 demo212.js。

输出

控制台中的输出如下 −

PS C:\Users\Amit\JavaScript-code> node demo212.js
The integer array value=
[
   101, 50, 70, 90,
   110, 90, 94, 68
]
The string array value=
[
   101, 50, 70, 90,
   110, 90, 94, 68
]

更新于: 01-10-2020

488 次浏览

开启你的职业生涯

完成课程即可获得认证

立即开始
广告
© . All rights reserved.