You can simply skip the longer line and add one character from both lines to your resulting line at each iteration. I do not think you need a regular expression:
a = 'LOVE'; b = '....'; var combinedString = ''; var largerLength = Math.max( a.length, b.length ); for( var i = 0; i < largerLength; i++ ) { combinedString += a.charAt(i) + b.charAt(i); }
The above code will work for strings of any length. In case you know in advance that both lines have exactly 4 characters, I think the fastest and most efficient way:
a = 'LOVE'; b = '....'; var combinedString = a.charAt[0] + b.charAt[0] + a.charAt[1] + b.charAt[1] + a.charAt[2] + b.charAt[2] + a.charAt[3] + b.charAt[3]; console.log( combinedString );
source share