๐Ÿ“– Map

๐ŸŽฏ new Map() โžก๏ธŽ Map ์ƒ์„ฑ

let map = new Map();
let map = new Map([[1, 2], [3, 4], [5, 6]]);
//map = Map(3) {1 => 2, 3 => 4, 5 => 6}

let userinfo = new Map([['name', "John"], ['name', "Sara"], ['age', "40"]]);
//userinfo = Map(2) {'name' => 'Sara', 'age' => '40'}

๐ŸŽฏ map.set() โžก๏ธŽ Map์— ์ž๋ฃŒ ์ž…๋ ฅ/์ œ๊ฑฐ/์ˆ˜์ •

//map: Map ์ด๋ฆ„
map.set('key', 'value');
//Map {'key'=> 'value'}

๐ŸŽฏ map.has() โžก๏ธŽ Map์— key ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ

map.has('key');
//true

๐ŸŽฏ map.get() โžก๏ธŽ Map์˜ value ๊ฐ€์ ธ์˜ค๊ธฐ

map.get('key');
//'value'

๐Ÿ“– Set

๐ŸŽฏ new Set() โžก๏ธŽ Set ์ƒ์„ฑ

//์˜ค๋ฆ„์ฐจ์ˆœ ์ง‘ํ•ฉ์ƒ์„ฑ
let set = new Set();
let set1 = new Set([1, 2, 1, 3, 7]);
//set1 = Set(4) {1, 2, 3, 7}

let set2 = new Set([{name: "John"}, {name: "Sara"}, {age: "40"}])
//{
//	0: {
//      	value: {
//          		name: "John"
//        }
//    }
//	1: {
//      	value: {
//          		name: "Sara"
//        }
//    }
//	2: {
//      	value: {
//          		age: "40"
//        }
//   }
//}

๐ŸŽฏ set.has() โžก๏ธŽ Set ์ž๋ฃŒ ๊บผ๋‚ด๋ณด๊ธฐ

set1;
// set1 = Set(4) {1, 2, 3, 7}

set1.has(3);
//true

for (let user of set2) {
  console.log(user);
}
//{name: "John"}
//{name: "Sara"}
//{name: "40"}

for (let user of set2) {
  console.log(user.name);
}
//John
//Sara

for (let user of set2) {
  console.log(user.age);
}
//40

๐ŸŽฏ set.add()/set.delete() โžก๏ธŽ Set์— ์ž๋ฃŒ ์ž…๋ ฅ/์ œ๊ฑฐ/์ˆ˜์ •

set.add(8);
// {1, 2, 3, 7, 8}
set.delete(8);
// {1, 2, 3, 7}

๐ŸŽฏ set.size โžก๏ธŽ Set ํฌ๊ธฐ

set1.size
//4
profile
๊ฐœ๋ฐœ๊ธฐ๋ก

0๊ฐœ์˜ ๋Œ“๊ธ€