Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App

JavaScript Set values() Method

Last Updated : 12 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The Set.values() method in JavaScript returns a new Iterator object that contains all of the items available in the set in a certain order. The order of values are in the same order that they were inserted into the set.

Syntax:

mySet.values()

Parameters:

  • This method does not accept any parameters.

Return Value:

  • The Set.values() method returns a new iterator object which holds the values for each element present in the set.

The below examples illustrate the Set.values() method:

Example 1:

JavaScript
let myset = new Set();  // Adding new element to the set myset.add("California"); myset.add("Seattle"); myset.add("Chicago");  // Creating a iterator object const setIterator = myset.values();  // Getting values with iterator console.log(setIterator.next().value); console.log(setIterator.next().value); console.log(setIterator.next().value); 

Output:

California
Seattle
Chicago

Example 2:

JavaScript
let myset = new Set();  // Adding new element to the set myset.add("California"); myset.add("Seattle"); myset.add("Chicago");  // Creating a iterator object const setIterator = myset.values();  // Getting values with iterator using // the size property of Set let i = 0; while (i < myset.size) {     console.log(setIterator.next().value);     i++; } 

Output:

California
Seattle
Chicago

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

S

shinjanpatra
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Methods
  • JavaScript-Set

Similar Reads

    JavaScript Set() Constructor
    The Javascript Set constructor is used to create Set objects. It will create a set of unique values of any type, whether primitive values or object preferences. It returns the new Set object. It mainly helps in creating a new set of objects which contains unique elements.Syntax:new Set()new Set(iter
    2 min read
    JavaScript Set size Property
    The Set.size property in JavaScript returns the number of elements in a Set. In other words, we can say that this property is used to get the current size of the set. If the Set is empty the size of the set will be returned as 0.Syntax:mySet.sizeReturn Type:Number of elements in the setExample 1: In
    2 min read
    JavaScript Set constructor Property
    JavaScript Set Constructor Property is used to return the Set constructor() for the object. It only returns the reference of the function and does not return the name of the function. In JavaScript set, it returns the function Set(){ [native code] }. Syntax Set.constructorParameter: It does not take
    1 min read
    JavaScript Set add() Method
    The Set.add() method in JavaScript is used to append an element with a specified value in a set. It modifies the existing set by appending the new element but does not return a new set. The Set.add() method does not modify the set if the element with a specified value already exists in the set.Synta
    3 min read
    JavaScript Set clear() Method
    The Set clear() method in JavaScript is used for the removal of all the elements from a set and making it empty. Syntax:mySet.clear();Parameters:This method does not accept any parameters.Return Value:Returns an undefined value.Example 1: Emptying set using Set clear() methodJavaScript// Create a ne
    3 min read
    JavaScript Set delete() Method
    The delete() method in JavaScript Set deletes an element from the set and returns true if the element existed and was successfully deleted. Otherwise, it returns false if the element does not exist.Syntax:mySet.delete(value);Parameters:value: It is the value of the element that is to be deleted from
    3 min read
    JavaScript Set entries() Method
    The Set.entries() method returns a new Iterator object that contains an array of [value, value] for each element in the Set object, in the order of their insertion. Although a Set does not contain key-value pairs, to keep similarities with the map.entries() method, it will return key-value pairs whe
    2 min read
    JavaScript Set forEach() Method
    The set.forEach() method is used to execute the function which is taken as a parameter and applied for each value in the set, in insertion order.Syntax:forEach(function(value, key, set) { /* ... */ }, thisArg)Parameters:Callback function: The function will be executed for each value and it takes thr
    3 min read
    JavaScript Set has() Method
    The Set.has() method in JavaScript is used to check whether an element with a specified value exists in a Set or not. It returns a boolean value indicating the presence or absence of an element with a specified value in a Set.Syntax:mySet.has(value);Parameters:value: It is the value of the element t
    2 min read
    JavaScript Set values() Method
    The Set.values() method in JavaScript returns a new Iterator object that contains all of the items available in the set in a certain order. The order of values are in the same order that they were inserted into the set.Syntax:mySet.values()Parameters:This method does not accept any parameters.Return
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences