在javascript中将整数数组转换为字符串数组 [英] convert integer array to string array in javascript
本文介绍了在javascript中将整数数组转换为字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下数组,
var sphValues = [1,2,3,4,5];
然后我需要转换上面的数组,如下所示
then I need to convert above array like as below one
var sphValues = ["1","2","3","4","5"];
我如何转换?
我用它来自动完成..
How can i convert? I used this for autocomplete..
推荐答案
你可以使用 map 并传递 String 构造函数作为函数,它将每个数字转换为字符串:
You can use map and pass the String constructor as a function, which will turn each number into a string:
sphValues.map(String) //=> ['1','2','3','4','5']
这不会改变sphValues。它将返回一个新数组。
This will not mutate sphValues. It will return a new array.
这篇关于在javascript中将整数数组转换为字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文