๊ฐ์ฒด

0

javascript

๋ชฉ๋ก ๋ณด๊ธฐ
7/34
post-thumbnail
post-custom-banner

๐Ÿ“ ๊ฐ์ฒด

์ฃผ์†Œ๋ก์— ์ ํ•ฉํ•œ ์ž๋ฃŒ ๊ตฌ์กฐ ์ž…๋‹ˆ๋‹ค.

๐Ÿ“Œ ๊ฐ์ฒด ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•
1. ์ค‘๊ด„ํ˜ธ๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
2. ํ‚ค - ๊ฐ’ ์Œ์€ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ํ•ด์ค๋‹ˆ๋‹ค.

let user = { firsrName : โ€˜Steveโ€™ ,  lastName : โ€™Leeโ€™ , email : โ€™Steve@naver.comโ€™ , city:โ€™seoulโ€™ };

๐Ÿ“Œ ๊ฐ’์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
1. dot notation

user.firstName;  //'Steve'
user.city;  //'Seoul'
  1. bracket notation (ํ‚ค๊ฐ’์ด ๋ณ€ํ• ๋•Œ)
user[โ€˜firstNameโ€™];  //โ€˜Steveโ€™
user[โ€˜cityโ€™]; //โ€˜Seoulโ€™
//->[ ] ์•ˆ์— โ€˜๋ฌธ์ž์—ด ํ˜•์‹์œผ๋กœ ์•ˆ๋“ค์–ด๊ฐ€๋ฉด ๋ณ€์ˆ˜๋ฅผ ๋œปํ•จ
  1. ๋ณ€์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ์ถœ๋ ฅํ•˜๊ธฐ
let a = โ€˜cityโ€™;
User.[city];  //โ€˜Seoulโ€™

๐Ÿ“Œ ๊ฐ’์ถ”๊ฐ€ํ•˜๊ธฐ

let user = { firsrName : โ€˜Steveโ€™ ,  lastName : โ€™Leeโ€™ , email : โ€™Steve@naver.comโ€™ , city:โ€™seoulโ€™ };
user[โ€˜cityโ€™] = โ€˜africaโ€™;
user.isPublic = true;
user.tags = [โ€˜#asdโ€™, โ€˜#werโ€™];

๐Ÿ“Œ ๊ฐ’ ์‚ญ์ œ

let user = { firsrName : โ€˜Steveโ€™ ,  lastName : โ€™Leeโ€™ , email : โ€™Steve@naver.comโ€™ , city:โ€™seoulโ€™ };
delete user.city;
let user = { firsrName : โ€˜Steveโ€™ ,  lastName : โ€™Leeโ€™ , email : โ€™Steve@naver.comโ€™ }

ํ‚ค๋ฅผ ์‚ญ์ œํ•˜๋ฉด ๊ฐ’์€ ๋‹น์—ฐํžˆ ๊ฐ™์ด ์‚ญ์ œ

๐Ÿ“Œ ๊ฐ์ฒด์— ํ‚ค ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ

let user = { firsrName : โ€˜Steveโ€™ ,  lastName : โ€™Leeโ€™ , email : โ€™Steve@naver.comโ€™ , city:โ€™seoulโ€™ };
โ€˜cityโ€™ in user ;  //true


 ๐Ÿ’• **์•Œ์•„๋‘๋ฉด ์ข‹์€ ํŒ ** 

for(let key in ๊ฐ์ฒด๋ช…) -> ๊ฐ์ฒด๋ฅผ ์ˆœํ™˜ํ•œ๋‹ค. 

Object.keys(๊ฐ์ฒด๋ช…).length ; ->๊ฐ์ฒด์˜  ํ‚ค ๊ฐœ์ˆ˜ 

obj1[key] = obj2 -> obj1 ์•ˆ์— obj2๊ฐ์ฒด๊ฐ€ ๋“ค์–ด๊ฐ„๋‹ค 
profile
๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ปํ•ญ์ƒ๋ฐœ์ „ํ•˜์ž ๐Ÿ”ฅ
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€