Merging of array in javascript or jquery -


var first = [ "a", "b", "c" ]; var second = [ "d", "e", "f" ]; 

my output should be

var final=["a~d","b~e","c~f"]; 

where '~' delimiter.

check if length of both arrays.

see comments inline in code:

var first = [ "a", "b", "c" ]; var second = [ "d", "e", "f" ];  var len = first.length > second.length ? first.length : second.length; // length of array having max elements  var separator = '~';  var final = [];  for(var = 0; < len; i++) {     // if no element present, use empty string     first[i] = first[i] ? first[i] : '';     second[i] = second[i] ? second[i] : '';       final.push(first[i] + separator + second[i]);     // add new element in new array } 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -