์๋ฐ์คํฌ๋ฆฝํธ ์ ์ฉํ ํจ์ ๋ชจ์
๊ฐ์ฒด ํค ์ด๋ฆ ๋ณ๊ฒฝํ๊ธฐ โ๏ธ ๊ฐ์ฒด const originObj = { old1: '๊ฐ1', old2: '๊ฐ2', old3: '๊ฐ3', old4: '๊ฐ4', old5: '๊ฐ5' }; const func = ({old1: new1, old2: new2, ...rest}) => { return {new1, new2, rest}; } const newObj = func(originObj); console.log(newObj); โ๏ธ ๊ฐ์ฒด ๋ฐฐ์ด const originList = [{ old1: '๊ฐ1', old2: '๊ฐ2', old3: '๊ฐ3', old4: '๊ฐ4', old5: '๊ฐ5' }, { old1: '๊ฐ1', old2: '๊ฐ2', old3: '๊ฐ3', old4: '๊ฐ4', old5: '๊ฐ5' }]; con..
2022. 8. 29.
javascript ๊ฐ์ฒด ํค ์ด๋ฆ ๋ณ๊ฒฝ
๊ฐ์ฒด ํค ์ด๋ฆ ๋ณ๊ฒฝํ๊ธฐ (๊ฐ์ฒด ๋ฐฐ์ด) map ์ธ์๋ก ๊ฐ์ฒด๋ฅผ ๊ตฌ์กฐ๋ถํดํ์ฌ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ๋ณ๊ฒฝํ๊ณ ์๋ก์ด ๊ฐ์ฒด๋ก ๋ฆฌํดํ๋ค. let origins = [{ old1: 'origins[0].old1', old2: 'origins[0].old2', old3: 'origins[0].old3' }, { old1: 'origins[1].old1', old2: 'origins[1].old2', old3: 'origins[1].old3' }]; let results = origins.map(({ old1: new1, old2: new2, ...rest }) => ({ new1, new2, ...rest })); ๊ฐ์ฒด ํค ์ด๋ฆ ๋ณ๊ฒฝํ๊ธฐ (๊ฐ์ฒด) let origin = { old1: 'origins[0].old1', old2..
2022. 7. 8.
javascript ๋ฐฐ์ด ๋ด ์ค๋ณต ๊ฐ ๊ตฌํ๊ธฐ
๋ฐฐ์ด ๋ด์์ ์ค๋ณต ๊ฐ์ ์ถ์ถํ๋ ๋ฐฉ๋ฒ์ด๋ค. ์๋ฅผ ๋ค์ด [1, 1, 2, 3, 5] ๋ฐฐ์ด์์ ์ค๋ณต ๊ฐ์ธ [1] ์ ๊ตฌํ๋ ๋ฐฉ๋ฒ์ด๋ค. ์ค๋ณต ๊ฐ์ ๊ตฌํด์ผ ํ๋ ๋์ ๋ฐฐ์ด์ด ๊ฐ์ฒด๋ฅผ ์์๋ก ๊ฐ๋ ๋ฐฐ์ด์ด๋ผ๋ฉด ๊ฐ์ฒด์์ ์ค๋ณต์ ๊ฒ์ฌํ ๋์๋ง ์ถ์ถํ๋ค. (์ค๋ณต์ด ๊ฐ์ฒด ๋ด ๊ฐ์ด ์๋๋ผ ๊ฐ์ฒด ์์ฒด๋ผ๋ฉด JSON.stringify() ๋ฑ์ผ๋ก ๋ณํํ์ฌ ํ์ธํด์ผ ํ๋ค.) // ๋ฐ์ดํฐ let arr = [{ "name": "ํ๊ธธ๋", "phoneNumber": "010-1111-1111" }, { "name": "๊น๊ธธ๋", "phoneNumber": "010-2222-2222" }, { "name": "๊ณ ๊ธธ๋", "phoneNumber": "010-3333-3333" }, { "name": "์๊ธธ๋", "phoneNumber": "..
2022. 6. 23.