JavaScript Set entries() method - JavaScript Tutorial

JavaScript Set entries() method

BLUF: This tutorial on JavaScript Set entries() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Set entries() method

Understanding JavaScript Set entries() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience