I'm trying to get sequential values from a dynamically generated array of numerical values, and add those sequential values together in pairs, in sequence. The generated array will always have an even number of values. As an example, let's say the array comes out to
myArray = [2, 23, 45, 128, 92, 3].
How can I use jQuery to iterate over the generated array and get values like this?
val1 = myArray[0] + myArray[1];
val2 = myArray[2] + myArray[3];
val3 = myArray[4] + myArray[5];
The array is dynamically generated, and as the list of items may increase or decrease, I don't want to hardcode existing key/values. I need to come up with a formula that will take into account the future addition or subtraction of the sequential pairs.
Any help would be greatly appreciated!