An online markdown blog and knowledge repository.
Presenter: Kassie Bradshaw, Python Alum
KB used replit.com as the presentation
JavaScript has 7 types of loops.
Just says "execute code within brackets".
Usually includes some sort of condition under which the loop exits.
for (Where is the loop going to start?, Loop runs while this condition is true, How much will variable be incremented while loop is running? ) { code }
Is an Array prototype method.
let myArray = ["one", "two", "three"];
arrayName.forEach(function(item, index){ do... });
Why use this instead of a for loop?
Can use the "arrow function" to operate on each iterable.
myArray.forEach( item => console.log(item));
Loops over an array, creating a new array and modify it with results from operations against the source array.
Usage: let newArray = myArray.map(item => { let newItem = 'Value: ${item}'; console.log(newItem); return newItem;});
Is meant to iterate over the properties of an object.
Can operate on arrays as well as objects, however:
ForOf loop is the newest loop released.
ForOf loop can iterate over any iterable object.
ForOf loop is a simplified version of the For() loop, in that code is shorter but just as effective.
let myObject = { school: "codefellows", activity: "pph", time: "noonish"};
let myArray = ["hi", "howedy", "how are ya?"];
Code expaining how to use For...In to return values by using the keys:
myArray.forIn(i => Console.Log( myArray[i] ));
(this needs to be verified).
There are a few ways?
break
statement e.g. if(j=2){break;}
.if ( condition ) { indexer = top indexer value};
.