3-09.Object Destructuring
2023. 3. 30. 09:26ㆍJavascript/자바스크립트 제대로 배워볼래?
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<script>
function getPerson() {
return {
firstName: "John",
lastName: "Doe",
age: 37,
email: "john@gmail.com",
city: "New York",
country:"USA"
};
}
var person = getPerson();
console.log(person); // {firstName: 'John', lastName: 'Doe', age: 37, email: 'john@gmail.com', city: 'New York', …}
console.log(person.firstName);
// 위와 같이 해도 되지만, 내가 받고 싶은 키만 넣어서 하면 되기도 한다
var {firstName, lastName} = getPerson();
console.log(firstName);
console.log(lastName);
</script>
</body>
</html>
'Javascript > 자바스크립트 제대로 배워볼래?' 카테고리의 다른 글
3-11.Promise (0) | 2023.03.30 |
---|---|
3-10.Array Destructuring (0) | 2023.03.30 |
3-08.Spread Operator (0) | 2023.03.30 |
3-07.Object Literal Syntax Extension !!! 0_0 (0) | 2023.03.30 |
3-06.Template Literals (0) | 2023.03.29 |