Learn about Different ways to loop in JavaScript Image by Tine IvaniÄŤ What is Loop ? Consider we need to print “hi” 5 times. If we don’t have loop , what we would be doing is console.log(“hi”);console.log(“hi”);console.log(“hi”);console.log(“hi”);console.log(“hi”); But , if we know how to use loop , then we can simplify the above code to for(let i = 1; i …
Tag Archives: 100daysofcode
Six ways to create an Array in JavaScript.
Learn Different ways to create JavaScript Arrays. Image by Clem Onojeghuo 1 . Using assignment operator var array = []; var array2 = [1,2,3,4,5]; 2. Using new operator new Array(length) ; Creates an array with length set to the number. length > 0 otherwise it will throw error var arr = new Array(2); arr; [empty Ă— 2] arr.length; …
Continue reading “Six ways to create an Array in JavaScript.”