Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9b84ca

Browse filesBrowse files
authored
Create Objecst
1 parent f70abbd commit b9b84ca
Copy full SHA for b9b84ca

File tree

1 file changed

+44
-0
lines changed
Filter options

1 file changed

+44
-0
lines changed

‎Objecst

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// defined by {} , can take in properties
2+
3+
let example1 = {
4+
firstName: 'Dylan', // firstName is key, 'Dylan' is value
5+
lastName: 'Israel',
6+
address: {
7+
city: 'Austin',
8+
state: 'Texas'
9+
},
10+
age: 30,
11+
cats: ['Milo', 'Tito', 'Achieles']
12+
};
13+
14+
console.log(example1.firstName); // produce first name
15+
console.log(example1.address.city);
16+
17+
example.age (example1.age);
18+
19+
// > 31
20+
21+
// if we want all the keys
22+
console.log(Object.keys(example1));
23+
// > ["firstName", "lastName", "address", "age", "cats"]
24+
25+
// if we want values as well
26+
console.log(Object.values(example1));
27+
// > ["Dylan", "Israel", {city: "Austin", state: "Texas"}, 31, ["Milo", "Tito", "Achieles"]]
28+
29+
// if we want to ask for a certain key
30+
console.log(example1.hasOwnProperty('firstName2'));
31+
// > false as it does now exist.
32+
33+
// ===================================== CHALLENGE ============================================
34+
35+
let example1 = {
36+
firstName: 'Dylan'
37+
};
38+
39+
let example2 = Object.assign({}, example1);
40+
41+
example2.lastName = 'Israel'; // instantiating a new object.
42+
43+
console.log(example1);
44+
console.log(example2);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.