///////////////////////////////////////
// Dot vs. Bracket Notation
const jonas = {
firstName: 'Jonas',
lastName: 'Schmedtmann',
age: 2037 - 1991,
job: 'teacher',
friends: ['Michael', 'Peter', 'Steven']
};
console.log(jonas);
console.log(jonas.lastName);
console.log(jonas['lastName']);
const nameKey = 'Name';
console.log(jonas['first' + nameKey]);
console.log(jonas['last' + nameKey]);
// console.log(jonas.'last' + nameKey)
const interestedIn = prompt('What do you want to know about Jonas? Choose between firstName, lastName, age, job, and friends');
if (jonas[interestedIn]) {
console.log(jonas[interestedIn]);
} else {
console.log('Wrong request! Choose between firstName, lastName, age, job, and friends');
}
jonas.location = 'Portugal';
jonas['twitter'] = '@jonasschmedtman';
console.log(jonas);
jonas.lastName와 jonas['lastName']은 똑같이 jonas 옵션안의 lastName의 값을 불러오는 기능을 한다
'공부자료 > 자바스크립트' 카테고리의 다른 글
섹션 2 Javascript Fundamentals part 2 - Looping Arrays, Breaking and Continuing (0) | 2021.09.20 |
---|---|
섹션 2 Javascript Fundamentals part 2 - Iteration: The for Loop (0) | 2021.09.20 |
섹션 2 Javascript Fundamentals part 2 - Object Methods (0) | 2021.09.20 |
섹션 2 Javascript Fundamentals part 2 - Introduction to Objects (0) | 2021.09.20 |
섹션 2 Javascript Fundamentals part 2 - Basic Array Operations (0) | 2021.09.19 |