๐ŸŒŸ 220713.TIL

Universeยท2022๋…„ 7์›” 14์ผ
0

study

๋ชฉ๋ก ๋ณด๊ธฐ
16/49
post-custom-banner

๊ฐ์ฒด์˜ ํ‘œ๊ธฐ๋ฒ•

์  ํ‘œ๊ธฐ๋ฒ•(dot notation) vs ๊ด„ํ˜ธ ํ‘œ๊ธฐ๋ฒ•(bracket notation)

let mySelf = {
	name: 'Kim',
  	age: 30,
  	hobby: 'codding',
    hometown: 'seoul'
}

mySelf.name // 'kim'
mySelf.age // 30

mySelf['hobby'] // 'codding'
mySelf['hometown'] // 'seoul'

์  ํ‘œ๊ธฐ๋ฒ•์€ ๊ด„ํ˜ธ ํ‘œ๊ธฐ๋ฒ•์— ๋น„ํ•ด ๊ฐ„๊ฒฐํ•˜์—ฌ ๊ฐ€๋…์„ฑ์ด ์ข‹๋‹ค
๊ทธ๋Ÿฐ๋ฐ

let seoulMan = 'hometown'

mySelf['hometown'] // 'seoul'
mySelf[seoulMan] // 'seoul'
mySelf.seoulMan // undefined

์ด์ฒ˜๋Ÿผ
๊ฐ์ฒด์˜ ํ”„๋กœํผํ‹ฐ์— ๋ณ€์ˆ˜๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋‹ค
๊ทธ๋ ‡๋‹ค๋ฉด

	mySelf.seoulMan = 'cityman';

๊ฐ์ฒด์— ๋ณ€์ˆ˜์™€ ๊ฐ™์€ ์ด๋ฆ„์˜ ํ‚ค๊ฐ€ ์žˆ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ ?

์ถ”๊ฐ€ํ•œ ๊ฐ์ฒด์˜ ์ƒํƒœ

let mySelf = {
	name: 'Kim',
  	age: 30,
  	hobby: 'codding',
    hometown: 'seoul'
  	seoulMan: 'cityman'
}

let seoulMan = 'hometown'
mySelf['hometown'] // 'seoul'
mySelf['seoulMan'] // 'cityman'
mySelf[seoulMan] // 'seoul'
mySelf.seoulMan // 'cityman'

์ด๋Ÿฐ์‹์œผ๋กœ ์ฒ˜๋ฆฌ๋œ๋‹ค

profile
Always, we are friend ๐Ÿงก
post-custom-banner

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