JavaScript

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฐ์ฒด ๋ณ‘ํ•ฉ ๋‹ค๋ฃจ๊ธฐ Object.assign() ๋ฉ”์†Œ๋“œ ๊ฐœ๋…๊ณผ ์‚ฌ์šฉ๋ฒ•

martinooo 2024. 7. 12. 17:31

 

 

 

 

 

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ ์ค‘์š”ํ•œ ๊ฐ์ฒด ์ง€์‹ ๊ณต๋ถ€ํ•˜๊ธฐ


 

 

 


๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฐ์ฒด์˜ ๊ฐœ๋…๊ณผ ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•

https://cometruedream.tistory.com/261

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ์กฐ์ž‘, JSON, ๋ฉ”์„œ๋“œ ๊ฐœ๋…๊ณผ ์‚ฌ์šฉ๋ฒ•

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ ์ค‘์š”ํ•œ ๋ฐฐ์—ด ์‚ฌ์ „ ์ง€์‹ ๊ณต๋ถ€ํ•˜๊ธฐ "> HTML ์‚ฝ์ž…๋ฏธ๋ฆฌ๋ณด๊ธฐํ•  ์ˆ˜ ์—†๋Š” ์†Œ์Šค ๋ฐฐ์—ด reduce() ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐhttps://cometruedream.tistory.com/259 HTML ์‚ฝ์ž…๋ฏธ๋ฆฌ๋ณด๊ธฐํ•  ์ˆ˜ ์—†๋Š”

cometruedream.tistory.com

 

 

๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฐ์ฒด Object.values(), Object.keys() ๋ฉ”์†Œ๋“œ ๊ฐœ๋…

https://cometruedream.tistory.com/264

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฐ์ฒด ๋‹ค๋ฃจ๊ธฐ Object.values() ํ•จ์ˆ˜ ๊ฐœ๋…๊ณผ ์‚ฌ์šฉ๋ฒ•

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ ์ค‘์š”ํ•œ ๊ฐ์ฒด ์ง€์‹ ๊ณต๋ถ€ํ•˜๊ธฐ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๊ฐ์ฒด์™€ ๋ฐฐ์—ด์€ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ ์ž๋ฃŒ๊ตฌ์กฐ ์ž…๋‹ˆ๋‹ค.javascript ๊ฐ์ฒด(object)๋Š” key์™€ value ํ˜•ํƒœ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ ๊ฐ์ฒด์—๋Š” ๋งŽ์€

cometruedream.tistory.com

 

๐Ÿคท‍โ™‚๏ธ Object.assign()๋ž€?


์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๊ฐ์ฒด๋Š” ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ ์ž๋ฃŒ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.

๊ฐ์ฒด๋ฅผ ์œ ์šฉํ•˜๊ฒŒ ๋‹ค๋ฃฐ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š” ๋‹ค์–‘ํ•œ ๋ฉ”์†Œ๋“œ๋“ค์ด ์กด์žฌํ•˜์ง€๋งŒ ๊ทธ์ค‘์—์„œ ๊ฐ์ฒด๋ฅผ ๋ณ‘ํ•ฉํ•˜๊ณ  ๊ฐ์ฒด๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ณ  ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ• ๋•Œ ์œ ์šฉํ•œ ๊ฐ์ฒด ๋ฉ”์†Œ๋“œ๋กœ Object.assign() ๋ฉ”์†Œ๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด๋ž€?

ํ•ด๋‹น ๊ธ€์—์„œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด์— ๊ฐœ๋…์„ ๋ณด์‹œ๋Š”๊ฒƒ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

https://cometruedream.tistory.com/261

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ์กฐ์ž‘, JSON, ๋ฉ”์„œ๋“œ ๊ฐœ๋…๊ณผ ์‚ฌ์šฉ๋ฒ•

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ ์ค‘์š”ํ•œ ๋ฐฐ์—ด ์‚ฌ์ „ ์ง€์‹ ๊ณต๋ถ€ํ•˜๊ธฐ "> HTML ์‚ฝ์ž…๋ฏธ๋ฆฌ๋ณด๊ธฐํ•  ์ˆ˜ ์—†๋Š” ์†Œ์Šค ๋ฐฐ์—ด reduce() ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐhttps://cometruedream.tistory.com/259 HTML ์‚ฝ์ž…๋ฏธ๋ฆฌ๋ณด๊ธฐํ•  ์ˆ˜ ์—†๋Š”

cometruedream.tistory.com

 

 

 

๐Ÿคท‍โ™‚๏ธ Object.assign() ์‚ฌ์šฉ๋ฒ•?


Object.assign() ๋ฉ”์†Œ๋“œ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๊ฐ์ฒด๋ฅผ ๋ณต์‚ฌ, ๋ณ‘ํ•ฉ, ์—…๋ฐ์ดํŠธ์— ์‚ฌ์šฉ๋˜๋Š” ๊ฐ์ฒด ๋ฉ”์†Œ๋“œ ์ž…๋‹ˆ๋‹ค. 

 

์‰ฝ๊ฒŒ ์ดํ•ดํ• ์ˆ˜ ์žˆ๋Š” ๊ฐœ๋… 2๊ฐ€์ง€

  • ๊ฐ์ฒด๋ณต์‚ฌ: ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋ฅผ ๋‹ค๋ฅธ ๊ฐ์ฒด์— ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌ
  • ๊ฐ์ฒด๋ณ‘ํ•ฉ: ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ์ฒด๋ฅผ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋กœ ๋ณ‘ํ•ฉ

 

1. ๊ฐ์ฒด ๋ณต์‚ฌ

์˜ˆ์ œ

let originalPhoneBook = { 
    "Alice": "123-456-7890" 
};

let copiedPhoneBook = Object.assign({}, originalPhoneBook);

console.log(copiedPhoneBook);
// ์ถœ๋ ฅ: { "Alice": "123-456-7890" }

 

์œ„์— ์˜ˆ์ œ์—์„œ originalPhoneBook ๊ธฐ์กด์— ๊ฐ์ฒด ๊ฐ’์„ ๊ฐ€์ง€๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.

copiedPhoneBook ๋ณ€์ˆ˜๋Š” Object.assign() ๋ฉ”์†Œ๋“œ๋ฅผ ํ™œ์šฉํ•ด์„œ originalPhoneBook ์ƒˆ๋กœ์šด ๊ฐ์ฒด์˜ ๊ฐ’์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ originalPhoneBook๊ณผ copiedPhoneBook ๊ฐ™์€ ๊ฐ’์˜ ๊ฐ์ฒด๋ฅผ ๋‹ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

2. ๊ฐ์ฒด ๋ณ‘ํ•ฉ

 

์˜ˆ์ œ

let phoneBook1 = { 
    "Alice": "123-456-7890" 
};

let phoneBook2 = { 
    "Bob": "987-654-3210" 
};

let mergedPhoneBook = Object.assign({}, phoneBook1, phoneBook2);

console.log(mergedPhoneBook);
// ์ถœ๋ ฅ: { "Alice": "123-456-7890", "Bob": "987-654-3210" }

 

์œ„์— ์˜ˆ์ œ์—์„œ phoneBook1์™€ phoneBook2 ๋‘๊ฐœ์— ๊ฐ์ฒด๋ฅผ Object.assign() ๋ฉ”์†Œ๋“œ๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ณ‘ํ•ฉํ•ฉ๋‹ˆ๋‹ค. 

 

์•Œ์•„๋‘๋ฉด ์ข‹์€ ๊ฟ€ํŒ

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ณ€์ˆ˜์™€ ์ƒ์ˆ˜์— ์ €์žฅ ๊ฐ’๊ณผ ๋‹ค๋ฅด๊ฒŒ ๊ฐ์ฒด๋Š” ๋‹ค๋ฅธ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ์— ๊ฐ์ฒด ๊ฐ’์„ ๋‹ด๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.

 

3. Object.assign({}, originalObject)์™€ Object.assign(originalObject) ์ฐจ์ด์ 

Object.assign() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋ฉด์„œ ๋ˆˆ์ฐ๋ฏธ๊ฐ€ ์ข‹์œผ์‹ ๋ถ„์€ 2๊ฐœ์˜ ๋ฐฉ์‹์„ ๋ณด์‹ค์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‘๊ฐœ์˜ ๋ฐฉ์‹์˜ ์ฐจ์ด์ ์— ๋Œ€ํ•ด์„œ ๊ฐœ๋…์„ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

object.assign({}, originalObject) ์˜ˆ์ œ

let originalPhoneBook = { 
    "Alice": "123-456-7890" 
};

let copiedPhoneBook = Object.assign({}, originalPhoneBook);

console.log(copiedPhoneBook);

 

์ด ๋ฐฉ์‹์€ ์ƒˆ๋กœ์šด ๊ฐ์ฒด {}๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ƒˆ๋กœ์šด ๊ฐ์ฒด์•ˆ์— originalPhoneBook ๋ณต์‚ฌํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

์ค‘์š”ํ•œ ์ ์€ copiedPhoneBook ์ƒˆ๋กœ์šด ๊ฐ์ฒด ๊ฐ’์„ ๋‹ด๊ณ ์žˆ์œผ๋ฉฐ originalPhoneBook ๋ณ€์ˆ˜๋Š” ๋ณ€ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

object.assign(originalObject)

let originalPhoneBook = { 
    "Alice": "123-456-7890" 
};

let phoneBook2 = { 
    "Bob": "987-654-3210" 
};

let copiedPhoneBook = Object.assign(originalPhoneBook, phoneBook2);

console.log(copiedPhoneBook);

console.log(originalPhoneBook);
//{Alice: '123-456-7890', Bob: '987-654-3210'}

 

์ด๋ฐฉ์‹์€ originalPhoneBook ๊ฐ์ฒด์— phoneBook2 ๋ณ‘ํ•ฉํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ originalPhoneBook ๋ณ€์ˆ˜๋Š” phoneBook2 ๊ฐ’์„ ๋ณ‘ํ•ฉํ•œ ๊ฐ์ฒด์˜ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์ค‘์š”ํ•œ์ ์€ originalPhoneBook๊ฐ์ฒด์˜ ๊ฐ’์ด ๋ฐ”๋€๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

์œ„์— 2๊ฐœ์˜ ์˜ˆ์ œ์˜ ์ฐจ์ด์ 

์œ„์— ๋‘๊ฐœ์˜ ์˜ˆ์ œ๋กœ Object.assign({}, ๊ฐ์ฒด), Object.assign(๊ฐ์ฒด1, ๊ฐ์ฒด2) ๋ฉ”์†Œ๋“œ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋Š”์ง€ ์•Œ์•„๋ณด์•˜๊ณ  ๋‘๊ฐœ์˜ ๋ฐฉ์‹์— ์ฐจ์ด์ ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.

 

๐Ÿคท‍โ™‚๏ธ ๋งˆ์ง€๋ง‰์œผ๋กœ


์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋‹ค์–‘ํ•œ ๊ฐ์ฒด ๋ฉ”์†Œ๋“œ๊ฐ€ ์กด์žฌํ•˜๋ฉฐ Object.assign() ๋ฉ”์†Œ๋“œ๋Š” ๊ฐ์ฒด๋ฅผ ๋ณต์‚ฌํ•˜๊ณ  ๋ณ‘ํ•ฉํ•˜๊ณ  ์—…๋ฐ์ดํŠธํ•˜๋Š”๋ฐ ์œ ์šฉํ•œ ๊ฐ์ฒด ๋ฉ”์†Œ๋“œ์ž…๋‹ˆ๋‹ค.

Object.assign() ์˜ˆ์ œ๋“ค์„ ๋ณด๋ฉด์„œ ๊ฐ์ฒด๊ฐ€ ์ €์žฅ๋˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ ๊ฐœ๋…๋„ ์ดํ•ดํ•˜๋Š”๊ฒƒ์ด ์ค‘์š”ํ•˜๋ฉฐ ์›๋ณธ์— ๊ฐ์ฒด๋ฅผ ์ˆ˜์ •ํ•˜๋Š”์ง€ ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š”์ง€ ๊ฐ์ฒด์˜ ๋งค์ปค๋‹ˆ์ฆ˜์„ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

 


 

์žฌ๋ฐŒ๋Š” ์˜ค๋Š˜์˜ ๋ ๋ณ„ ์šด์„ธ ๋ณด๊ณ  ๊ฐ€์„ธ์š”! 

 

 

https://cometruedream.tistory.com/247

 

[React] Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผ className ์ปค์Šคํ…€

๐Ÿคท‍โ™‚๏ธ Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผํ”„๋กœ์ ํŠธ ์ง„ํ–‰์ค‘ ๋ฐฐ๋„ˆ ๋งํฌ์— URL ๊ธธ์ด๊ฐ€ ๋„ˆ๋ฌด ๊ธธ์–ด์„œ 3์ค„ ํšจ๊ณผ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค. React + Tailwind CSS ์…‹ํŒ…๋œ ํ”„๋กœ์ ํŠธ ์—ฌ์„œ CSS ํŒŒ์ผ & style ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/243

 

NestJS Lifecycle (์ƒ๋ช…์ฃผ๊ธฐ) ๊ฐœ๋…

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ Nest JS ๊ฐœ๋…?Nest JS๋Š” Node JS ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ ์ž…๋‹ˆ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์ƒ๋‹นํžˆ ์˜ค๋žซ๋™์•ˆ Express ๊ธฐ๋ฐ˜์œผ๋กœ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์—์„œ ์••๋„์ ์ธ ์ 

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/242

 

๋ฆฌ์•กํŠธ Vite Proxy ํ™œ์šฉํ•œ CORS ์˜ค๋ฅ˜ ํ•ด๊ฒฐ

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋ก ํŠธ์—”๋“œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ต์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ  ๊ธ€์„ ๋ณด์‹œ๋ฉด ๋” ๋งŽ์€ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค^^ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ตhttps://comet

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/241

 

React ํด๋”๊ตฌ์กฐ FSD ๊ธฐ๋Šฅ ๋ถ„ํ™œ ์„ค๊ณ„ ์•„ํ‚คํ…์ฒ˜

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ์— ์•ž์„œ ํด๋” ๊ตฌ์กฐ, ์„ค๊ณ„์— ๋Œ€ํ•œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์€ ์ƒ๋‹นํžˆ ์–ด๋ ต๋‹ค. ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์— React FSD ํด๋”๊ตฌ์กฐ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์„ค๊ณ„ํ•  ์˜ˆ์ •์ด๋ผ์„œ FSD ์•„ํ‚คํ…

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/244

 

์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋Š” Prisma ๋ช…๋ น์–ด ์ •๋ฆฌ

๐Ÿคท‍โ™‚๏ธ Prisma ๋ช…๋ น์–ด ๋ณธ๋ก ์— ์•ž์„œ Prisma๋ž€?Nest JS ํ”„๋ ˆ์ž„์›Œํฌ์™€ Prisma ORM์„ ํ™œ์šฉํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ Prisma๋Š” Node JS ๊ธฐ๋ฐ˜์— ํ”„๋ ˆ์ž„์›Œํฌ/๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ์ƒํ˜ธ์ž‘์šฉ์ด ์ž˜๋˜๋ฉฐ Prisma + DB ์—ฐ๋™์œผ

cometruedream.tistory.com