Let's see Javascript Map and Set. We'll see Javascript specific things and something is good to know. Learning test is written using Jasmine. Please refer Jasmine usage which I wrote before if you have interest it.
1. map basic
You can iterate elements of map using for-of statement. As see in [line 11], You can access the element using [key, value] form. The equality of key is evaluate both type and value using identity operator "===".
2. object vs map
Let's compare object and map. The attribute(key) of object should be defined using string, but map can use any type as a key. We can know the size of map using size method, but object need to iterate to calculate its size manually.
3. set basic
As you can see in [line 16], the key of map is also evaluate both type and value using identity operator "===".
4. array and set
As see in [line 5] , When convert array to set, duplicated element are removed except one.
5. Reference
- MDN - https://developer.mozilla.org/en/docs/Web/JavaScript
- Jasmine - http://jasmine.github.io/2.3/introduction.html
댓글 없음:
댓글 쓰기