Skip to content

Commit 0b6ed75

Browse files
author
codewithghan
committed
two files spread and rest oprators and copying objects
1 parent 2bc47f3 commit 0b6ed75

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

copy_of_objects.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// const obj = {
2+
// fname:'ghan',
3+
// age: 20,
4+
// location: 'Noida'
5+
// };
6+
7+
8+
const objDeep = {
9+
fname:'ghan',
10+
age: 20,
11+
location: 'Noida',
12+
address: {
13+
city:'US'
14+
}
15+
};
16+
17+
// const newObj = { ...obj }; // Shalow copy
18+
// const newObj = Object.assign({}, obj); // Shalow copy
19+
const newObj = JSON.parse(JSON.stringify(objDeep)); // deep copy
20+
newObj.address.city = "UK12";
21+
console.log(objDeep);
22+
console.log(newObj);

spread.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const myArr = [10,20,30];
2+
3+
// console.log(...myArr);
4+
// const myStr = 'John';
5+
// console.log(...myStr);
6+
7+
// const myObj = {
8+
// fname:'john',
9+
// lname: 'doe',
10+
// age: 30
11+
// };
12+
13+
// const newObj = {...myObj};
14+
// newObj.age = 10;
15+
// console.log(newObj);
16+
// console.log(myObj);
17+
18+
// Spread example
19+
20+
// const bioArr = ['john', 30, 'US'];
21+
22+
// function getBio(fname, age, country) {
23+
// return `my name is: ${fname} and age is: ${age}`;
24+
// }
25+
26+
// const newbioArr = getBio(...bioArr);
27+
28+
// console.log(newbioArr);
29+
30+
// Rest
31+
32+
33+
// function getBio(fname, ...info) {
34+
// return info;
35+
// }
36+
37+
38+
// const getbioInfo = getBio('ghan', 30, 'delhi');
39+
// console.log(getbioInfo);
40+
41+
42+
// remove dublicate values from array
43+
44+
// const arr = [2,3,2,4,3,5,3,6];
45+
46+
// console.log(...new Set(arr));
47+
48+
49+
50+
51+
52+
53+
54+

0 commit comments

Comments
 (0)