Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to add up all numbers in an array

var numbers = [10, 20, 30, 40] 
var sum = 0;
for (var i = 0; i < numbers.length; i++) {  sum += numbers[i]}
Comment

add numbers in array

const years = [1, 2, 3, 4]
let total = 0;
for (let i = 0; i < years.length; i++) {

    total += years[i]

}

console.log(total)

//answer willl be 10
Comment

how to add up all numbers in an array

const numbers = [10, 20, 30, 40] 
add = (a, b) =>  a + b
const sum = numbers.reduce(add)
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add alternate image in img tag in react 
Javascript :: Warning: Prop `className` did not match. Client and server rendered different classes . 
Javascript :: js pow 
Javascript :: select all elements javascript 
Javascript :: await useeffect javascript 
Javascript :: virtual properties in mongoose model 
Javascript :: express.static 
Javascript :: adonis hasone 
Javascript :: jquery closert 
Javascript :: alphabet as array javascript 
Javascript :: docker react 
Javascript :: change key in array of objects javascript 
Javascript :: install aos angular 10 
Javascript :: how to display api data in html 
Javascript :: js input type range on hover 
Javascript :: node red admin password setting 
Javascript :: get full month from date javascript 
Javascript :: how to use url parameters in react 
Javascript :: dynamic select option dropdown in jquery 
Javascript :: react forwardref 
Javascript :: convert decimal to binary javascript 
Javascript :: axios call error handling 
Javascript :: upload and read json file javascript 
Javascript :: moment check greater than current time 
Javascript :: check if string contains at least one number javascript 
Javascript :: string includes substring javascript 
Javascript :: react native app crashes without error 
Javascript :: promise in forloop 
Javascript :: autocomplete is not working in jsx file vs code 
Javascript :: window.location.href another tab 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =