This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const employee = { | |
name: 'Siddharth', | |
age: 30, | |
salary: { | |
annual: '100K', | |
hourly: '$50' | |
} | |
}; | |
const copyOfEmployee = JSON.parse(JSON.stringify(employee)); // => DEEP COPY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const employee = { | |
name: 'Siddharth', | |
age: 30, | |
salary: { | |
annual: '100K', | |
hourly: '$50' | |
} | |
}; | |
const copyOfEmployee = {...employee, salary: { ...employee.salary }}; // => DEEP COPY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const employee = { | |
name: 'Siddharth', | |
age: 30, | |
salary: { | |
annual: '100K', | |
hourly: '$50' | |
} | |
}; | |
const copyOfEmployee = {...employee}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const employee = { | |
name: 'Siddharth', | |
age: 30, | |
salary: { | |
annual: '100K', | |
hourly: '$50' | |
} | |
}; | |
const copyOfEmployee = Object.create( employee); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const employee = { | |
name: 'Siddharth', | |
age: 35, | |
salary: { | |
annual: '100K', | |
hourly: '$50' | |
} | |
}; | |
const copyOfEmployee = Object.assign({}, employee); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("********Nested ARRAYS********"); | |
const c = [1, 2, [3, 4]]; | |
const d = JSON.parse(JSON.stringify(c)); // => JSON Methods | |
console.log('c => ', c); | |
console.log('d => ', d); | |
/* | |
********Nested ARRAYS******** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("********Nested ARRAYS********"); | |
const c = [1, 2, [3, 4]]; | |
const d = []; | |
c.forEach(el => d.push(el));; | |
console.log('c => ', c); | |
console.log('d => ', d); | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("********Nested ARRAYS********"); | |
const c = [1, 2, [3, 4]]; | |
const d = c.slice(0); | |
console.log('c => ', c); | |
console.log('d => ', d); | |
/* | |
********Nested ARRAYS******** | |
c => [ 1, 2, [ 3, 4 ] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("********Nested ARRAYS********"); | |
const c = [1, 2, [3, 4]]; | |
const d = c.map(el => el);; | |
console.log('c => ', c); | |
console.log('d => ', d); | |
/* | |
********Nested ARRAYS******** | |
c => [ 1, 2, [ 3, 4 ] ] | |
d => [ 1, 2, [ 3, 4 ] ] | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("********Nested ARRAYS********"); | |
const c = [1, 2, [3, 4]]; | |
const d = [...c]; | |
console.log('c => ', c); | |
console.log('d => ', d); | |
/* | |
c => [ 1, 2, [ 3, 4 ] ] | |
d => [ 1, 2, [ 3, 4 ] ] | |
*/ | |
d[0] = 0; |
NewerOlder