Created
July 27, 2016 12:54
-
-
Save solidpple/987a789eaeeb78870b628ee5f94fbd47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dictionary 사용하는 방법 | |
var dictObject = {} | |
dictObject['banana'] = '바나나'; | |
dictObject['hong'] = '홍'; | |
dictObject['monkey'] = '원숭이'; | |
console.log(dictObject) // Object {banana: "바나나", hong: "홍", monkey: "원숭이"} | |
// Dictionary 출력 | |
for (var key in dictObject) { | |
console.log("key : " + key +", value : " + dictObject[key]); | |
} | |
// Dictionary 추가, 제거 | |
dictObject['elephant'] = '코끼리'; // 추가 | |
delete dictObject['elephant']; // 삭제 (제대로 삭제 되면 true, 아니면 false) | |
// 모든 key를 가져오는 방법 | |
Object.keys(dictObject); // ["banana", "hong", "monkey"] | |
// Dictionary 길이 구하는 방법 | |
Object.keys(dictObject).length; // 3 | |
// key를 체크하는 방법 | |
"moneky" in dictObject // true | |
"elephant" in dictObject // false | |
// key의 마지막 값 가져오는 방법 | |
var lastKey = Object.keys(dictObject)[Object.keys(dictObject).length - 1] | |
console.log("last key = " + lastKey); | |
// monkey | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment