-
Notifications
You must be signed in to change notification settings - Fork 0
/
Objects.js
48 lines (40 loc) · 1013 Bytes
/
Objects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* key value pairs
no need of index to access data*/
//creating an object
const person={
firstName:"Erem",
lastName:"Yeager",
favNum: 8,
favColors:["blue","green"]
}
//accesing objects by their KeyName
person["firstName"]; //dont forget the quotes, js converts the keynames to strings
person.firstName;//now forget it
//creating a variable pointing to a string using the data of person
let tatakae=person["firstName"]+person["lastName"];
//modifying objects
person.favNum=9; //u can also insert something of a different datatype
person["firstName"]="Zeke";
person["Father"]="Grisha"; //adding key value pairs
//nesting arrays and objects
//array containing objects
const shoppingCart=[
{
product:"ODM Gear",
price:50
},
{
product:"Serum",
price:20
}
]
//object containing arrays
const student={
firstName:"Armin",
lastName:"Arlert",
strengths:["Leadership","Compassion"]
exams:{
midterm:91,
endterm:95
}
}