A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Arrays and adding

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    117

    Arrays and adding

    I have one array that has 5 elements, and another also having 5.

    I want to add the elements from the second into the first, but the first value of each is to be added, and then the second of each.

    Kinda like if I had Array1 and Array2

    Array1[0]+=Array2[0]
    Array1[1]+=Array2[1]
    and so on

    Is there an easy way to say that the arrays are to add themselves, but only the appropriate values?

    I'm sorry if this is choppy, but it's my first time using arrays and them really working.

    Thanx

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Something like this:
    code:

    var a = Array(1, 2, 3, 4);
    var b = Array(5, 6, 7, 8);
    var c = Array();
    for (var i = 0; i < a.length; i++)
    {
    c.push(a[i] + b[i]);
    }
    trace(c); // 6,8,10,12


    ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center