Create Set Objects In JavaScript
In JavaScript, Set objects are collections of unique values.
Set objects efficiently store, retrieve, and manipulate distinct values. Any data type can be stored as values, including other sets.
A new Set object is created via the Set constructor.
Common Syntax Of Set Objects In JavaScript
Glossary:
Unique
The single one of its kind
Value
The representation of some entity that can be manipulated by a program
Object
Data structure storing related data as key-value pair
Common Set Objects
Name | Description | Example |
---|---|---|
Set() | Create an empty set. | new Set(); |
Name | Description | Example |
JavaScript Set Objects Snippet
// OjamboShop.com Learning JavaScript Set Objects Tutorial let names = new Set(); // Create Set let ages = new Set([23, 33, 44]); // Create & Initialize Set let clone = new Set(ages); // Created Clone Set console.log(typeof names); console.log(names); console.log(typeof ages); console.log(ages); console.log(typeof clone); console.log(clone);
Usage
You can use any IDE or text editor and the web browser to compile and execute JavaScript code. For this tutorial, the OjamboShop.com Learning JavaScript Course Web IDE can used to input and compile JavaScript code for the Set object.
Open Source
JavaScript follows the ECMAScript standard and is licensed under the W3C Software License by web browser vendors and runtime environment vendors. This allows commercial use, modification, distribution, and allows making derivatives proprietary.
Learn Programming Courses:
Get the Learning JavaScript Course for your web browser on any device.
Learn Programming Books:
Learning Javascript Book is available as Learning JavaScript Paperback or Learning JavaScript Ebook.
Conclusion:
JavaScript makes it easy to use the Set object. Use the Set object to store unique values of any data type.
If you enjoy this article, consider supporting me by purchasing one of my OjamboShop.com Online Programming Courses or publications at Edward Ojambo Programming Books
References:
- Learning JavaScript Course on OjamboShop.com
- Learning Python Course on OjamboShop.com
- Learning PHP Course on OjamboShop.com
- Learning JavaScript Paperback on Amazon
- Learning JavaScript Ebook on Amazon
- Learning Python Ebook on Amazon
- Learning PHP Ebook on Amazon
- OjamboServices.com For Custom Websites, Applications & Tutorials