-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.js
More file actions
39 lines (28 loc) · 900 Bytes
/
set.js
File metadata and controls
39 lines (28 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Set() in JavaScript
// sets are a unique array because items can only be added once
// each item will have a unique value
// has a really nice api for managing items inside
// cant access items individualy
// not index based
const people = ['Jason', 'Nathan', 'Jared'];
const names = new Set(people);
// add items
// names.add('Jason');
// names.add('Nathan');
// names.add('Jared');
// names.add('Bobby');
// when using a set key and values are the same thing
const humans = names.values();
// for(const name of humans) {
// console.log(name);
// }
// delete item
//names.delete('Jason');
//console.log(names.size);
// logs out set clears it then sets a clear one
// console.log(names);
// names.clear();
// console.log(names);
console.log(names.has('Jason')); // jason vs Jason has to be an exact match
//console.log(names);
// in the teaching they use .values(), .keys(), .entries