Skip to content

Commit 856dfb8

Browse files
committed
some change in object code
1 parent 5218379 commit 856dfb8

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

Object_basic.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ iam.name="abhi"
3939

4040
// for use symbol in object as a symbol we will use squre bracket in key they will can acces key as a symbol
4141

42-
// console.log(iam);
42+
console.log(iam);
4343

4444
// we can treet function as variable
4545
// it is a way to create a fuction for an object
@@ -52,6 +52,7 @@ function greetingg (){
5252
console.log(`hello ${iam.name} your age is ${iam.age} and your email id is ${iam.email} `);
5353
}
5454

55+
// here declearing function for a object we can use this for acces object data
5556
iam.greeting = function (){
5657
console.log(`hello ${this.name} is ${this.age} and your email id is ${this.email} `);
5758
}

Object_part2.js

+104-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,108 @@ const tinderuser= new Object() //sigleton object
88
tinderuser.age=18
99
tinderuser.IsLogIn=true
1010

11-
console.log(tinderuser);
11+
// console.log(tinderuser);
1212

13+
// nested object : means object in object
14+
// declearation
15+
const regularUser={
16+
email:"Some@gmail.com",
17+
fullname:{ //fullname is object
18+
userfirstName:"abhishek",
19+
userLastName:"pandey"
20+
}
21+
}
22+
23+
// we can acces nested object by dot
24+
// we will use ? if will conect by api response otherwise we will need to use ifelse means if object is availiable then will give output otherwise leave
25+
// console.log(regularUser.fullname);
26+
// console.log(regularUser.fullname?.userLastName);
27+
28+
// same as array we can combine object also
29+
const Obj1={a:45,b:67}
30+
const Obj2={c:85,d:35}
31+
32+
// const Obj3={Obj1,Obj2}
33+
// console.log(Obj3);
34+
35+
// we can perform function also as array
36+
const obj3=Object.assign(Obj1,Obj2)//output :{ a: 45, b: 67, c: 85, d: 35 } , first will get target means empaty it will modify target by sorce by merge and will give target as a new object
37+
38+
// Object.assign(target,sorce one or more seprate by commas)
39+
//all values will combine and new object will get
40+
// will create a new object as object1,and Object2
41+
console.log(obj3);
42+
console.log(Obj1);
43+
44+
// one more spread method for combine object as we done in array
45+
const obj3_={...Obj1,...Obj2} //it is a very simplest way for combine
46+
47+
// data come from database as many object in array
48+
49+
const data_=[
50+
{
51+
username:"avi898",
52+
password:"6869896"
53+
},
54+
{
55+
username:"dsfji898",
56+
password:"6869896"
57+
},
58+
{
59+
username:"avinas898",
60+
password:"6869896"
61+
}
62+
,
63+
{
64+
}
65+
]
66+
67+
// console.log(data_[1].password);//here we written 1 because we all looking from array so we will give index then we will get value from object
68+
69+
// console.log(Object.keys(tinderuser)); //when we will use Object then we need to tell about which object we all talking
70+
// we will get output in array mean now we can put loop on that
71+
// it is very important
72+
73+
// as we get keys as array we can get value also as array
74+
// console.log(Object.values(tinderuser));
75+
76+
77+
// console.log(Object.entries(tinderuser));// by entries will create each keys and value as a value
78+
79+
// very important in what data user or we are performing loop want we have not then can crash so we will use a property for check is value availiable in Object if will avaliable we will get output true otherwise false
80+
81+
console.log(tinderuser.hasOwnProperty("ru"));
82+
83+
84+
// ******************* D_structuring******************
85+
86+
// here declearing a object which name is course
87+
const course={
88+
coursename:"python",
89+
price:898,
90+
course_teacher:"code_with_harry"
91+
}
92+
93+
// course.course_teacher
94+
95+
// Mostly people use this way
96+
// value extract from object
97+
const {course_teacher:instructer}=course // we can change name of key also after use : instructer
98+
console.log(instructer); //it d_structuring
99+
// if anywhere we will see curly braces thenwe will know there happenig destucturing
100+
101+
// **********************API*************************
102+
103+
// when we will give our work to anyone that is api
104+
// in previous time api call come in xml but now come in json
105+
// json
106+
// {
107+
// // its a json
108+
// // in json keys and value will in string
109+
// "myname":"ravi",
110+
// " coursename" : "python in hindi",
111+
// "price": "50"
112+
113+
// }
114+
115+
// sometimes we will get api in array for in array will see many objects

0 commit comments

Comments
 (0)