Javascript Looping Constructs

JavaScript Looping Constructs

These are some looping constructs that I seem to use frequently....

USAGE: Copy and paste the code samples below into the Javascript console in your browser, then simply hit return on your keyboard to see the code in action.

//standard looping code
let numbers = [1, 2, 3, 4, 5];

function sumUp() {
  let result = 0;
  let toAdd=[];
  for (let i = 0; i < numbers.length; i++) {
    result += toAdd[i];
  return result;

let testResults = [1.23, 3.12, 5.33];
for (let testResult of testResults) {

Link your website to this page! Copy and paste the URL below:
Copyright 2020. All Rights Reserved.