constfoo= { someArray:[1,2,3]};for(element offoo.someArray){console.log(element);}//same as abovefor (var i =0; i <foo.someArray.length; i++) {console.log(foo.someArray[i]);}
7
You can loop over an array in an array. Just add an additional [index] after the first [index]
constfoo= [ ["0,0","0,1","0,2"], ["1,0","1,1","1,2"], ["2,0","2,1","2,2"]];for(row of foo){for(element of row){console.log(element); }}//same as abovefor (let i =0; i <foo.length; i++) {for (let j =0; j < foo[i].length; j++) {console.log(foo[i][j]); }}
Combine objects, arrays, and functions more than one level deep
8
You can create a function that returns an object. Just add the . after the () since the return value of the function is an object
You can create an object that has a method that returns an object that has another method
constfoo= {someMethod:()=>{return {someMethod:()=>{console.log('both methods can have the same name!'); } } }}foo.someMethod().someMethod(); //logs 'both methods can have the same name!'
18
You can create an object that has a method that returns a function
constfoo= {someMethod:()=>{return ()=>{console.log('hi') } }}foo.someMethod()();//logs hi
19
You can create an array that has a function that returns an object
constfoo= [1,'apple', ()=>{return { someProperty:'some value' } }];foo[2]().someProperty; //some value
20
You can create an array that has a function that returns an object that has an array