[js] deep copy lodash

Seorang Lee·2022년 2월 25일
0

업무를 하는 도중 deep copy를 해야할 상황에 자주 놓인다.

deep copy에는 다양한 방법이 있지만 lodash가 쓰기에 나의 경우 직관적이라서
자주 쓸 것 같아 메모해둔다.

  • 사용이유 : 내용은 같지만 참조값이 다른 별개의 객체를 만들기 위함

  • 사용방법

    _.cloneDeep()

  • 사용예시

import * as _from 'lodash';

let arr = [
	{a :1},
    {b:"hi"},
    {c : true}
   ]
   
newArr = _.cloneDeep(arr);

arr === newArr //false
profile
hello :-) This is Rang , I'm front-end engineer . here is my study note. welcome

0개의 댓글