ForEach loop in javascript




Link to my programming Video Library:
https://courses.LearnCodeOnline.in

Desktop: https://amzn.to/2GZ0C46
Laptop that I use: https://amzn.to/2Goui9Q
Wallpaper: https://imgur.com/a/FYHfk

Facebook: https://www.facebook.com/HiteshChoudharyPage
homepage: http://www.hiteshChoudhary.com
Download LearnCodeOnline.in app from Google play store and Apple App store

Disclaimer:
It doesn’t feel good to have a disclaimer in every video but this is how the world is right now.
All videos are for educational purpose and use them wisely. Any video may have a slight mistake, please take decisions based on your research. This video is not forcing anything on you.

All Amazon links are affiliate links (If any).

Original source


24 responses to “ForEach loop in javascript”

  1. So, if you have 3 ID names of DIVs in array, you can .pop() or .shift() one of them randomly and add to the rest a classes names
    var myArray = ['div', 'div2', 'div3'];
    var removeLast = myArray.pop();
    myArray.forEach(function(divName){
    document.getElementByID(divName).classList.add("redFromCSS");
    }) //and JS will list them one by one and add forEach that redFromCSS. Amazing… I use that trick to display: none my divs wich i dont use in CSS animations. I put all my divs name in array, then remove that i will use and rest of them in array i cut out by adding css style to wipe that divs. 😁

  2. I'm a brown guy as well so don't take offense, but your videos are the only coding ones I can understand because your accent isn't as strong as some of the others on Youtube. I'm definitely subscribing.

  3. ##ASSIGNMENT

    let arr=[]
    arr.push("Breakfast")
    arr.push("Lets write some code")
    arr.push("gaming time")
    arr.push("Lunch time")
    arr.push("write some code again!!")
    arr.push("Evening work")
    arr.push("have dinner")
    arr.push("Bed time")

    arr.forEach(function(task,index){
    console.log(`Your task ${index+1} is: ${task}`)
    })

  4. //forEach loop for entire months
    const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

    months.forEach(function(month, index){
    console.log(`month no ${index+1} is ${month}`);
    })

    //Todo List
    const todos = ['Go to Gym', 'Make dinner', 'Sleep for 6 hours']

    todos.forEach(function(todo, index){
    console.log(`My no ${index+1} task for day is ${todo}`)
    })

Leave a Reply