views:

136

answers:

1

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

+5  A: 

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"]
CMS
CMS's code is correct.
Michael Stone
thanks, the (a) in the $.map(a), is that the name of the first variable or is it sth different.thanks
amir
sorry to bother you again, is it possible to add spaces between A1 letters too, to make it look like A 1,B 2 or A * 1, B * 2thanks
amir
@amir, just change the return to `return n + ' ' + b[i];`
CMS