Sets in ES6

Description

A-Level Javascript (ES6) Note on Sets in ES6, created by James Drummond on 17/06/2015.
James Drummond
Note by James Drummond, updated more than 1 year ago
James Drummond
Created by James Drummond over 9 years ago
2
0

Resource summary

Page 1

Every item in a set is guaranteed to be unique - an item will not be added to a set if it already exists.So you don't have to iterate every element of an array to see if it exists.var collection = new Set([1, 2, 3, 4, 5]);var newElements = [4, 8, 10]; for(var i = 0; i collection.add(newElements[i]);}

Useful methods and properties Set.prototype.size - size of the set Set.prototype.constructor() - Takes array or other iterable as argument Set.prototype.add(value) - add an item to the set Set.prototype.delete(value) - delete an item from the set Set.prototype.has(value) - see if an item exists in the set Set.prototype.clear() - remove all elements from the set Set.prototype.forEach() - Iterate over the items of a set in insertion order Set.prototype.entries() - Obtain an iterator to loop through the set's elements Set.prototype.values() - returns an iterator object containing the values of the elements of the set

Show full summary Hide full summary

Similar

Maps in ES6
James Drummond
Arrow functions
James Drummond
Quiz - Object Oriented Javascript
arunram.krish
Examen Fundamentos Basicos de Programación
Jose Valderrama0721
Test I. Introduction to web technologies
Angel Martínez Rodriguez
JavaScript Fundamentals
Andrew Watters
Front-End Web Development
Chanthy Ngin
Javascript - Quiz - Jan 2016
arunram.krish
OpenSource Programming
Faheem Ahmed
Javascript basics
James Drummond
jQuery Basics functions and method
Victor Bini