Map 객체
키와 값을 서로 매핑시켜 저장하며 저장된 순서대로 각 요소들을 반복적으로 접근할 수 있다
✔ 키가 같으면 이전값에 덮어쓴다
var map = new Map();
map.set('java',100);
map.set('oracle',90);
map.set('html',100);
map.set('spring',90);
map.set('oracle',100);
console.log(map.size);//4
//.has 키 존재여부
console.log(map.has('css'));
// 키에 대한 값 반환 없으면 undefined
console.log(map.get('css'));
//.delete 삭제
map.delete('spring');
console.log('--------------------');
//순회
for(let [key,value] of map){
console.log(key+' : '+value);
}
console.log('--------------------');
map.forEach((value,key) => console.log(key+' , '+value));
console.log('--------------------');
// 전체 삭제
map.clear();
console.log(map.size);//0
// 대괄호(배열)를 이용한 Map 객체 만들기
let map2 = new Map(
[
['java',100],
['html',95],
['oracle',90]
]
);
map2.forEach((value,key) => console.log(key+' , '+value));
key 값이 중복이 없어야할때 써야 할꺼 같고 키값이 Obj와 다르게 어떤값도 가능하다는게 차이점이다
map운 음식 먹고싶다...🤣