[TIL] Day12 #๊ฐ์ฒด

Beanxxยท2022๋…„ 5์›” 11์ผ
0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
12/120
post-thumbnail

[TIL] Day12
[SEB FE] Day12

โ˜‘๏ธย ๊ฐ์ฒด

  • ํ‚ค์™€ ๊ฐ’ ์Œ(key-value pair)์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Œ. (๋ฐฐ์—ด๊ณผ ๋‹ฌ๋ฆฌ ์ˆœ์„œ ์ •๋ณด๊ฐ€ ์—†์Œ)
    - ๊ฐ์ฒด๋Š” ์†์„ฑ์— ์ˆœ์„œ๋Œ€๋กœ ์ ‘๊ทผํ•˜์ง€ ์•Š๊ณ , key๋ฅผ ํ†ตํ•ด์„œ value์— ์ ‘๊ทผ

    let user = {
        firstName: 'Soobin',
        lastName: 'Choi',
        email: 'tnqls1211v@gmail.com'
    };
    
    // key: firstName, lastName, email
    // value: 'Soobin', 'Choi', 'tnqls1211v@gmail.com'

๐Ÿ“Žย ๊ฐ์ฒด์˜ ๊ฐ’ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

  1. Dot notation: user.firstName;

  2. Bracket notation: user[โ€™firstNameโ€™];

    โœ‹ย key๋ฅผ ๊ฐ์‹ธ์ค„ ๋•Œ โ€™โ€™, โ€œโ€, ``(๋ฐฑํ‹ฑ) ๋ชจ๋‘ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

    โœ‹ย user[firstName]; ์ฒ˜๋Ÿผ key๋ฅผ ๊ฐ์‹ธ์ฃผ๋Š” ๊ฒƒ์ด ์—†์œผ๋ฉด ์ •์˜๋˜์ง€ ์•Š์€ ๋ณ€์ˆ˜๋ฅผ ์ฐธ์กฐํ•˜๋ฏ€๋กœ ReferenceError
    โ‡’ key๋ฅผ ๋ฌธ์ž์—ด ํ˜•์‹์œผ๋กœ ์ „๋‹ฌํ•ด์•ผ ํ•จ

๐Ÿ‘‰๐Ÿปย user[โ€™firstNameโ€™] === user.firstName; โ‡’ true


๐Ÿ“Žย ๊ฐ์ฒด์˜ ๊ฐ’ ์ถ”๊ฐ€ & ์‚ญ์ œ & ํ™•์ธ

  • ์ถ”๊ฐ€: ๊ฐ์ฒด ์•ˆ์— ์—†๋Š” ํ‚ค&๊ฐ’์„ ํ• ๋‹นํ•ด์ฃผ๋ฉด ๊ฐ์ฒด์— ์ถ”๊ฐ€
  • ์‚ญ์ œ: delete ํ‚ค์›Œ๋“œ๋กœ ์‚ญ์ œ
  • ํ™•์ธ: in ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•ด ํ•ด๋‹น ํ‚ค์˜ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ
 let user = {
 	firstName: 'Soobin',
 };
 
 user.lastName = ['Choi'];
 user['Country'] = 'Korea';
 
 ------->
 
 let user = {
 	firstName: 'Soobin',
 	lastName: 'Choi',
 	Country: 'Korea'
 }
 
 delete user.Country;  // key&value ์Œ ๋ชจ๋‘ ์‚ญ์ œ
 
 ------->
 
 let user = {
 	firstName: 'Soobin',
 	lastName: 'Choi'
 }
 
 'firstName' in user;  // true
 'Country' in user;    // false


โ˜‘๏ธย etc

โžฐย ์ข…ํ•ฉํ€ด์ฆˆ & ์—ฐ์Šต๋ฌธ์ œ๋ฅผ ํ’€๋ฉด์„œ ๊ธฐ์–ตํ•ด์•ผ ํ•  ๊ฐœ๋…๋“ค ๊ธฐ๋ก

  • splice(์ œ๊ฑฐํ•  ์š”์†Œ์˜ index, ๋ช‡๋ฒˆ์งธ ์š”์†Œ๊นŒ์ง€, ์ œ๊ฑฐํ•œ ํ›„ ๋Œ€์‹  ์ถ”๊ฐ€ํ•  ์š”์†Œ) (๊ธฐ๋ณธ ๋ฐฐ์—ด ๋ณ€๊ฒฝ O)
    • ๋ฐฐ์—ด ๋ฉ”์„œ๋“œ๊ฐ€ ์›๋ณธ ๋ฐฐ์—ด์„ ๋ณ€๊ฒฝํ•˜๋Š”์ง€ ํ™•์ธ ๊ฐ€๋Šฅ ์‚ฌ์ดํŠธ: https://doesitmutate.xyz/
  • pop(), push(), unshift(), shift() ๋“ฑ์˜ ์›๋ณธ ๋ฐฐ์—ด์ด ๋ณ€๊ฒฝ๋˜๋ฉด์„œ ๋ฐ˜ํ™˜๋˜๋Š” ํ˜•ํƒœ๊ฐ€ ์›๋ณธ ๋ฐฐ์—ด์ด ์•„๋‹ ๊ฒฝ์šฐ์—” ๋ฐฐ์—ด๋งŒ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ์ฝ”๋“œ๊ฐ€ ํ•„์š”
    let arr = [1, 2, 3, 4];
    arr.push(100) // return 5 (length)
    return arr;   // return [1, 2, 3, 4, 100] (๋ณ€๊ฒฝ๋œ ๋ฐฐ์—ด)
  • ๋ฐฐ์—ด์ด ๋นˆ ๋ฐฐ์—ด์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•: arr.length === 0
  • for ~ in๋ฌธ์„ ํ†ตํ•ด์„œ ๊ฐ์ฒด์˜ ๋ชจ๋“  key์— ์ ‘๊ทผํ•˜๊ณ  ์ถœ๋ ฅ ๊ฐ€๋Šฅ
    function iteratation(obj) {
    	for (let key in obj) {
    		obj[key]
    	}
    }
  • for ~ of๋ฌธ์€ string, array ๋“ฑ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฐ˜๋ณต๋ฌธ (๊ฐ์ฒด์—์„œ๋Š” ์‚ฌ์šฉ๋˜์ง€ ์•Š์Œ)
    • for (let ele of arr) === for (let i = 0; i < arr.length; i += 1)
  • Object.entries(): for ~ in๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋กœ ์ฃผ์–ด์ง„ ๊ฐ์ฒด ์ž์ฒด์˜ enumerable ์†์„ฑ [key, value] ์Œ์˜ ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜
  • Object.keys(): ์ฃผ์–ด์ง„ ๊ฐ์ฒด์˜ key๋“ค์„ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜
  • Object.values(): ์ฃผ์–ด์ง„ ๊ฐ์ฒด์˜ value๋“ค์„ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜
  • slice(0,-1) : ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ์š”์†Œ๋“ค ๋ฐ˜ํ™˜
    let arr = [1, 2, 3, 4, 5]
    arr.slice(0, -1) // [1, 2, 3, 4]
  • ๋ฐ˜๋ณต๋ฌธ, ์กฐ๊ฑด๋ฌธ ๋“ฑ์—์„œ continue -> ๊ฑด๋„ˆ ๋œ€, break -> ์—ฌ๊ธฐ์„œ ๋ฐ˜๋ณต๋ฌธ/์กฐ๊ฑด๋ฌธ ๋


โœ… 05.11 ์ƒˆ๋ฒฝ์— TED ๊ฐ•์—ฐ ์‹œ์ฒญ
๐Ÿ‘‰๐Ÿป Bill Gates - 'The next outbreak? We're not ready'
๐ŸŽค ์ธ๋ฅ˜๋Š” ์งˆ๋ณ‘์˜ ์œ„ํ—˜์— ํฌ๊ฒŒ ๋…ธ์ถœ๋˜์–ด ์žˆ์ง€๋งŒ ์ด์— ๋Œ€ํ•œ ๋Œ€๋น„๊ฐ€ ๋งŽ์ด ๋ถ€์กฑํ•˜๋‹ค๋Š” ๋‰˜์•™์Šค์˜ ๊ฐ•์—ฐ์ด๋‹ค. ์—๋ณผ๋ผ ์งˆ๋ณ‘์„ ์˜ˆ๋กœ ๊ฐ•์—ฐ์ด ์ง„ํ–‰๋œ๋‹ค. ์†Œ๋ฆ„์ธ๊ฑด 2015๋…„ ๊ฐ•์—ฐ์ธ๋ฐ ํ˜„์žฌ ์ฝ”๋กœ๋‚˜ ์งˆ๋ณ‘์— ๋Œ€ํ•œ ์งˆ๋ณ‘์˜ ์œ„ํ—˜ ๋…ธ์ถœ์— ๋Œ€ํ•ด ์ €๊ฒฉํ•œ๋“ฏํ•œ ๋‚ด์šฉ์ด์—ˆ๋‹ค. ๋งŒ์•ฝ ์ „์— ์ธ๋ฅ˜๊ฐ€ ๋ฐ”์ด๋Ÿฌ์Šค์— ๋Œ€ํ•œ ์งˆ๋ณ‘์˜ ๋Œ€๋น„์ฑ…์— ํž˜์„ ๋งŽ์ด ์ผ๋‹ค๋ฉด ์ด๋ ‡๊ฒŒ๊นŒ์ง€ ์ฝ”๋กœ๋‚˜๊ฐ€ ์‹ฌํ•ด์ง€์ง€ ์•Š์•˜์„์ˆ˜๋„ ์žˆ์—ˆ์„๊นŒ..?
profile
FE developer

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