Javascript - Get Sum of Numbers in Array

Version1
LanguageJavascript
CategoryArrays
Rating
   6 (1 votes)
DescriptionThis function gets the sum of all numeric values in an array. If an array element is not numeric, then it will be ignored

If you are sure that all elements in the array are valid numbers you could use a simple Array.reduce() statement.
Instructionsvar myArray=[1,2,3,'albert',4,5]
var arraySum = SumArray(myArray);
console.log(arraySum);
Code



Comments
No comments have been added
Leave your comment/rating
 

Related Scripts:

No related scripts were found.

Tags



Back to main scripts page