Skip to content

Instantly share code, notes, and snippets.

View siddharth-sunchu's full-sized avatar

Siddharth Sunchu siddharth-sunchu

  • Dallas TX
View GitHub Profile
const employee = {
name: 'Siddharth',
age: 30,
salary: {
annual: '100K',
hourly: '$50'
}
};
const copyOfEmployee = JSON.parse(JSON.stringify(employee)); // => DEEP COPY
const employee = {
name: 'Siddharth',
age: 30,
salary: {
annual: '100K',
hourly: '$50'
}
};
const copyOfEmployee = {...employee, salary: { ...employee.salary }}; // => DEEP COPY
const employee = {
name: 'Siddharth',
age: 30,
salary: {
annual: '100K',
hourly: '$50'
}
};
const copyOfEmployee = {...employee};
const employee = {
name: 'Siddharth',
age: 30,
salary: {
annual: '100K',
hourly: '$50'
}
};
const copyOfEmployee = Object.create( employee);
const employee = {
name: 'Siddharth',
age: 35,
salary: {
annual: '100K',
hourly: '$50'
}
};
const copyOfEmployee = Object.assign({}, employee);
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********
@siddharth-sunchu
siddharth-sunchu / ForEach.js
Last active June 26, 2021 22:25
ForEach.js
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);
/*
@siddharth-sunchu
siddharth-sunchu / sliceMethod.js
Last active June 26, 2021 22:25
sliceMethod.js
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 ] ]
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 ] ]
*/
@siddharth-sunchu
siddharth-sunchu / Arrays-SpreadOperator.js
Last active June 26, 2021 22:22
Arrays-SpreadOperator
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;