akano1
akano1

Reputation: 41614

how to match the value of two variables in Jquery

I was just wondering how I can match the value of two variable, for example if I have

 var A = [1,2,3];
 var b = [A,B,C];

how can I output the first value of each and second value of each and so on, so the output will become

 A1,B2,C3

thanks

Upvotes: 1

Views: 480

Answers (1)

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827416

Using jQuery.map:

var a = ['A','B','C'];
var b = [1,2,3];

var result = $.map(a, function(n, i){
  return n + b[i];
}); // ["A1", "B2", "C3"]

Upvotes: 5

Related Questions