for-Each In JavaScript With Example

Introduction and Usage

for-Each In JavaScript, the forEach() function iterate the elements of an array once one by one in order. Using for-Each() function or method we also iterate object elements.

forEach In JavaScript With Example


currentValueThe value of the current element. (Required)
indexThe array index of the current element. (Optional)
arrThe array object the current element belongs to. (Optional)

Example of forEach in JavaScript



  • In the above example, we create an array.
  • Then we iterate that array element using forEach() method.
  • And method stores the output of an iterated array on that parameter.

Iterate Object Using for-Each in JavaScript


“foo: bar” “baz: 42”

  • In the above example, we create an object and assign it to a CONST type.
  • Object.entries(obj) returns an array or an object’s own enumerable string.
  • Then we use forEach() with Object.entries(obj).
  • In this process, first object converts to an array then iterate by the forEach() function.

See the Pen Foreach and Map Example JS by Bikash Panda (@phpcodertech) on CodePen.

Here is the complete explanation with example.

To know more Object.entries() – JavaScript | MDN (

Also Read

Happy Coding..!

Was this article helpful?
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 175

One thought on “for-Each In JavaScript With Example

Leave a Reply

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

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort -

- milanobet giriş - gizabet giriş -
perabet giriş
- betkanyon giriş -

jojobet giriş

We are now accepting guest posting and creation of back-links.
This is default text for notification bar