From 02faf2583878671f236d75f1ad2b7618a91c142e Mon Sep 17 00:00:00 2001 From: yuichimukai Date: Thu, 15 Apr 2021 11:58:07 +0900 Subject: [PATCH] object and buili in --- index.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index f8fa901..9db0ee6 100644 --- a/index.js +++ b/index.js @@ -81,17 +81,6 @@ const array = [1, 5, 10, 15, 20]; // console.log(filterEven(array)); console.log(array.filter(isEven)); -const obj = { - a: 1, - b: 2, - c: 3, -}; - -for (const key in obj) { - const value = obj[key]; - console.log(`key:${key}, value:${value}`); -} - for (const value of array) { console.log(value); } @@ -123,3 +112,20 @@ const object1 = { key: undefined }; if (object1.hasOwnProperty("key")) { console.log("'object1'は'key'プロパティを持っている"); } + +const objee = { + a: { + b: "objのaプロパティのbプロパティ", + }, +}; + +console.log(objee?.a?.b); + +const shallowClone = (obj) => { + return Object.assign({}, obj); +}; + +const obj = { a: "a" }; +const cloneObj = shallowClone(obj); +console.log(cloneObj); +console.log(obj === cloneObj);