js 数组转化为字符串的方法

1,toString()

会把数组内的值用逗号拼接转化为字符串

let a = [1,2,3,4,5,6,7,8,9,0];

let s = a.toString();

console.log(s); //返回字符串“1,2,3,4,5,6,7,8,9,0”

2,toLocalString()

会把数组内的值用逗号拼接转化为字符串

let a = [1,2,3,4,5,6,7,8,9,0];

let s = a.toLocalString()

console.log(s); //返回字符串“1,2,3,4,5,6,7,8,9,0”

3,join

会把数组内的值用指定分隔符拼接转化为字符串

let a = [1,2,3,4,5,6,7,8,9,0];

let s = a.join('/')

console.log(s); //返回字符串“1/2/3/4/5/6/7/8/9/0”

你可能感兴趣的:(javascript,前端)