0% found this document useful (0 votes)
4 views2 pages

Set: Maintaining Insertion Order

A Set is a collection that only allows unique values and maintains the order of insertion. It utilizes a hash table for faster operations such as adding, deleting, and searching, and does not have indexed positions like arrays. Sets can be created from arrays or strings and can be iterated using loops like for...of or forEach.

Uploaded by

vickychaum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Set: Maintaining Insertion Order

A Set is a collection that only allows unique values and maintains the order of insertion. It utilizes a hash table for faster operations such as adding, deleting, and searching, and does not have indexed positions like arrays. Sets can be created from arrays or strings and can be iterated using loops like for...of or forEach.

Uploaded by

vickychaum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Set

Set is a special type of collection that only collect unique data no


duplicates are allowed.

Key features
Unique value only.
Keeps order: items are returned in the same order as you inserted
them.
Faster operations at the Backend set uses something called
Hash table, which make adding, deletion, searching very fast.
No index unlike array set have doesn’t have numbered
positions(index).
For…. Of loop or forEach loop can be used.
// Creating set
1. From an array:
Let v1=new set([10,20,10,12,23,20])
[Link](v1);
2. From String
Let v2= new se([10,20,30,10,30,14])
[Link](v2);

//How elements are ordered in set

 Using for …. Of
Let sample = new set();
[Link](“qw”);
[Link](“qws”);
[Link](“qxw”);
Let d=[Link]();
For(let val of d){
[Link](val);
}

You might also like