JAVASCRIPT ARRAY 相加 問題

假設我有2個ARRAY
var arr1= [1,2,3,4,5,6];

var arr2= [3,6,9,12,15,18];
for (i=0; i<arr1.length; i++)
  {
  
sum[i]=firstArray[i]+secondArray[i];
}
alert ( sum );

我想把2個array +在一起

想要結果如下
4,8,12,16,20,24

求師兄解答 THX

??? didn't your code already doing what you ask?

TOP

i can not see the result that i want....some logical error on my code

TOP

var arr1= [1,2,3,4,5,6];

var arr2= [3,6,9,12,15,18];

for (i=0; i<arr1.length; i++)
  {
  
sum[i]=arr1[i]+arr2[i];
}
alert ( sum );

i don know the for loop whehter any things to add or remove

TOP

var arr1= [1,2,3,4,5,6]
var arr2= [3,6,9,12,15,18]
var sum=[]

for (i=0; i<arr1.length; i++)
{
sum[i]=arr1[i]+arr2[i]
}
alert ( sum )

TOP

try
for (var j=0; j<sum.length;j++){
       alert(sum[j]);
}
or
var_dump(sum);

TOP

THX C HING!

TOP

本帖最後由 domeso 於 2012-6-15 06:52 編輯

REMOVED

TOP