-
Notifications
You must be signed in to change notification settings - Fork 0
/
10. iterables.js
50 lines (40 loc) · 876 Bytes
/
10. iterables.js
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
40
41
42
43
44
45
46
47
48
49
50
/*
array and strings are iterable
objects are not iterable
iterables are those on which for-of loop works
and that have length property
objects are not iterable
other iterables...
*/
/*
Set(any iterable)
unique items only (no duplicate)
no index-based access (order is not guaranteed)
set have it's own methods
it does not have length property
but can be used with for-of loop
*/
set = new Set([1,2,3])
set.add(4)
// boolean has(value)
set.has(5)
// ----------------
/*
Map object (key value pairs)
keys can be of any data type
*/
// create
person = new Map()
// set data
person.set("firstname", "asad")
person.set(1, "12")
person.set(true, false)
// get data
person.get("firstname")
person.get(1)
person.get(true)
// get keys (it is iterable can be used with for-of)
person.keys()
// for(key of person.keys())
console.log(person.get(a))
// console.log(person)