By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > how to loop through two arrays in javascript
JavaScript

how to loop through two arrays in javascript

Admin
Last updated: 2022/06/23 at 2:14 PM
Admin
Share
2 Min Read
how to loop through two arrays in javascript

Hello guys, In this article we will learn how to loop through two arrays in javascript at same time. we are use forEach to loop through two arrays.

Contents
How to loop through two arrays in javascript Using forEach ?ConclusionYou may also like:

How to loop through two arrays in javascript Using forEach ?

To use forEach to loop through 2 arrays at a similar time in JavaScript, we are able to use the index parameter of the forEach callback to get the part with a similar index from the second array. If both arrays have the same length then you can use index to log elements from other array.

var array1 = [1, 2, 3, 4];
var array2 = [5, 6, 7, 8];

array1.forEach(function(item, index){
  console.log(item, array2[index])
});

Output:

1 5
2 6
3 7
4 8
how to loop through two arrays in javascript

Here we have two array array1 and array2.These two array have same length. to call array1.forEach with a callback that gets the element from array2 with the same index.

Conclusion

To use forEach to loop through 2 arrays at an similar time in JavaScript, we will use the index parameter of the forEach and get the same index from the second array.

You may also like:

  • How To Make Number Guessing Game JavaScript
  • Build a Simple Number Memorising Game In JavaScript
  • Build a Simple Digital Clock In JavaScript

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Posted by Admin
Follow:
Rocoderes is a blog you can learn HTML, CSS, JavaScript, React Js and Python along with creative coding stuff and free source code files.
Previous Article what is a proxy server What Is A Proxy Server? How Proxy Server Works? Complete Guide
Next Article Space War Game How To Make Space War Game Using HTML, CSS & JavaScript
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?