Jieunny์˜ ๋ธ”๋กœ๊ทธ

Unit 8. [JS]๊ฐ์ฒด ๋ณธ๋ฌธ

CodeStates/learning contents

Unit 8. [JS]๊ฐ์ฒด

Jieunny 2022. 12. 22. 11:51

๐Ÿ“ฃ  ๊ฐ์ฒด

โœ”๏ธ key, value ์Œ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ํ‚ค์™€ ๊ฐ’ ์‚ฌ์ด๋Š” ' : '์œผ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.

โœ”๏ธ ' { } ' ๋กœ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ , ํ‚ค-๊ฐ’ ์Œ ๋ผ๋ฆฌ๋Š” ' . ' ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.

let user = {
	firstName: 'Kim',
	lastNaame: 'jieun',
	email: 'ccomo0313@naver.com',
	city: 'uijeongbu';
};

 

โœ”๏ธ ๊ฐ’์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

โžฐ Dot notation

๊ฐ์ฒด ์„ ์–ธ์— ์ •ํ•ด์ง„ key ์ด๋ฆ„์ด ์žˆ์„ ๋•Œ๋งŒ ์ด์šฉ๊ฐ€๋Šฅ

user.firstName;	// 'Kim'
user.city;	// 'uijeongbu'

โžฐ Bracket notation : `` ๋˜๋Š” '' ๋˜๋Š” "" ์œผ๋กœ key๋ฅผ ๊ฐ์‹ธ์ค˜์•ผ ํ•จ. 

key ๊ฐ’์ด ๋™์ ์œผ๋กœ ๋ณ€ํ•  ๋•Œ ์‚ฌ์šฉ (ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ key๋ฅผ ๋ฐ›์•„์˜ฌ ๋•Œ)

user['firstName'];	// 'Kim'
user['city'];	// 'uijeongbu'

 

โœ”๏ธ dot/bracket notation ์œผ๋กœ ๊ฐ’ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ

tweet['category'] = '์žก๋‹ด';
tweet.isPublic = true;

 

โœ”๏ธ delete ๋กœ ์‚ญ์ œ ๊ฐ€๋Šฅ

delete tweet.category;

 

โœ”๏ธ in ์œผ๋กœ ํ‚ค๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ ๊ฐ€๋Šฅ

'content' in tweet;	//false

 

โœ”๏ธ Object.keys(obj) ๋กœ ๊ฐ์ฒด์˜ ์ „์ฒด ํ‚ค ๋ฐฐ์—ด๋กœ ๋ฐ›์•„์˜ค๊ธฐ

โœ”๏ธ Object.values(obj) ๋กœ ๊ฐ์ฒด์˜ ์ „์ฒด ํ‚ค ๋ฐฐ์—ด๋กœ ๋ฐ›์•„์˜ค๊ธฐ