-
Notifications
You must be signed in to change notification settings - Fork 1
/
Objects2.js
53 lines (41 loc) · 1.2 KB
/
Objects2.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
49
50
51
52
53
// Objects
// Array Declartion
const prasannaArray = [
'Prasanna',
'Mallisetty',
20,
'Automation Tester',
['Michael', 'Peter', 'Steven'],
];
// Object : Key : Value pairs
// Object literal syntax - literally writng the object content
const prasanna = {
firstName: 'Prasanna',
lastName: 'Mallisetty',
age: 20,
job: 'Automation Test Analyst',
friends: ['Michael', 'Peter', 'Steven'],
};
console.log(prasanna);
// Dot Notation(Dot Operator)
console.log(prasanna.lastName);
// Bracket Notation
console.log(prasanna['lastName']);
// Bracket Notation: we can use the expression within Brackets, where as we cannot do the same in dot notataion
const nameKey = 'Name';
console.log(prasanna['first' + nameKey]);
console.log(prasanna['last' + nameKey]);
const interestedIn = prompt(
'What do you want to know about Prasanna? Choose between firstName, lastName, age, job'
);
console.log(interestedIn);
console.log(prasanna[interestedIn]);
if (prasanna[interestedIn]) {
console.log(prasanna[interestedIn]);
} else {
console.log('Wrong request! Choose between firstName, lastName, age, job');
}
// Adding new properties
prasanna.location = 'Sydney';
prasanna['twitter'] = '@Prasanna';
console.log(prasanna);