Hi i wonder if anyone can help, I’m trying to write a program in JS to add the elements of two arrays together - ie firstArray = [1,2,3,4,5,6,7,8,9] secondArray = [2,3,4,5,6,7,8,9,10]…I need to know how to add the first element in firstArray to the first element in secondArray and display the result.

I have the data in the arrays already and have writen this:-

var onlineVotesArray = new Array (41,37,43,11,59,21,36);
var paperVotesArray = new Array (22,3,15,11,7,1,10);
var candidateArray = new Array ("Mrs J Smith", " Mrs H J Rowe", " Ms Brown", " A N Other"," Mr White"," Ms I M Blue", " Mr P D Jones");
var totalVotesArray = new Array ();
	for (i = 0, l = candidateArray.length; i < l; i++)
	document.write(candidateArray _+ ' has ' + onlineVotesArray *+ ' Online votes and ' +*_ 

_ paperVotesArray + ’ Paper votes giving them a total of ’ + ’ votes.’ +'
* }
but I do not know how to add the elements together, I thought of putting:- totalVotesArray = ((onlineVotesArray) + (paperVotesArray)); but that does not work - help please!_

Before your for-loop initialize the array to have the correct size:


In your for-loop just add the arrays on a per-element-basis: