Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

clone object in typescript

//1.Shallow copy:
let Copy = {...yourObject}
//2.Deep Copy: a. through recusive typing functionality:
let Cone = DeepCopy(yourObject);
public DeepCopy(object: any): any
{
  if(object === null)
  {
    return null;
  }
  const returnObj = {};
  Object.entries(object).forEach(
  ([key, value]) =>{
    const objType = typeof value
  if(objType !== "object" || value === null){
     returnObj[key] = value;
  }
  else{
  	returnObj[key] = DeepCopy(value);
  }
}
//b.Hardway: repeat the following expanstions for all complex types as deep as you need
let Copy = {...yourObject, yourObjsComplexProp: {...yourObject.yourObjsComplexProp}}
Comment

PREVIOUS NEXT
Code Example
Typescript :: regex remove brackets and contents 
Typescript :: vsc typescript auto build on save 
Typescript :: React & TypeScript Chrome Extension Development [2021] 
Typescript :: python get first n elements of list 
Typescript :: react routes not working after build 
Typescript :: too many requests jquery laravel 
Typescript :: form control adding disabled and validators 
Typescript :: arguments in rust 
Typescript :: angular http 
Typescript :: how to target all child elements css 
Typescript :: nodejs exec exit code 
Typescript :: typescript array of objects interface 
Typescript :: classes in typescript 
Typescript :: typescript break for each 
Typescript :: throw error typescript 
Typescript :: actionscript 
Typescript :: different types of bread 
Typescript :: separate subplots in python 
Typescript :: arrow function in typescript 
Typescript :: How to specify output directory in TypeScript? 
Typescript :: flutter check if app is in foreground 
Typescript :: ts singleton pattern 
Typescript :: Prevent anchor tag to move to up when we click on it 
Typescript :: add if not exists lodash object list 
Typescript :: fgets input from user 
Typescript :: basic variable typescript 
Typescript :: import xml elements in kotlin 
Typescript :: isnull or empty typescript 
Typescript :: serenity.is center open dialog 
Typescript :: angular animation done event type typescript 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =