我需要字符串中每个字母的字符串Double
abc - > aabbcc
我试试这个
var s = "abc";
for(var i = 0; i < s.length ; i++){
console.log(s+s);
}
Run Code Online (Sandbox Code Playgroud)
O/P
> abcabc
> abcabc
> abcabc
Run Code Online (Sandbox Code Playgroud)
但是我需要
为aabbcc
帮我
使用String#split,Array#map和Array#join方法.
var s = "abc";
console.log(
// split the string into individual char array
s.split('').map(function(v) {
// iterate and update
return v + v;
// join the updated array
}).join('')
)Run Code Online (Sandbox Code Playgroud)