Home » JavaScript Set forEach() Method

JavaScript Set forEach() Method

by Online Tutorials Library

JavaScript Set forEach() method

The JavaScript Set forEach() method executes the specified function once for each value in the Set object. It maintains an insertion order.

Unlike Map, the Set object doesn’t use key externally. To keep the values unique it uses the key internally. Thus, Set considers the value of element as a key.

Syntax

The forEach() method is represented by the following syntax:

Parameter

callback – It represents the function to execute.

value1, value2 – The value1 represents the key of the element whereas value2 represents the value. Both arguments contains the same value.

set – It represents the current Set object.

thisArg – It represents the value that treats as this when executing callback.

JavaScript Set forEach() method example

Let’s see a simple example of forEach() method

Test it Now

Output:

Fetching values :  key[jQuery] = jQuery  key[AngularJS] = AngularJS  key[Bootstrap] = Bootstrap  

You may also like