JavaScript Set entries() method

The entries method of the JavaScript Set generates a new set iterator object. This object comprises an array of [value, value] pairs for each individual element within the set. It preserves the order of insertion.

Syntax

The entries function is depicted using the subsequent syntax:

Example

setObj.entries()

Return Value

A fresh instance of a set iterator is created, which comprises an array structured as [value, value] for every element present.

JavaScript Set entries method example

In this section, we will explore the entries method by examining a range of examples.

Example 1

Let's see a simple example of entries method.

Example

<script>

var set = new Set();

set.add("jQuery");

set.add("AngularJS");

set.add("Bootstrap");

var itr=set.entries();

for(i=0;i<set.size;i++)

  {

document.writeln(itr.next().value+"<br>");

  }

  </script>

Output:

Output

jQuery,jQuery

AngularJS,AngularJS

Bootstrap,Bootstrap

Example 2

Let's see the same example in a different way.

Example

<script>

var set = new Set();

set.add("jQuery");

set.add("AngularJS");

set.add("Bootstrap");

var itr=set.entries();

for(let elements of itr)

  {

document.writeln(elements+"<br>");

  }

  </script>

Output:

Output

jQuery,jQuery

AngularJS,AngularJS

Bootstrap,Bootstrap

Input Required

This code uses input(). Please provide values below: