Skip to content

Commit 6744381

Browse files
author
jaime-medhome
committed
objects
1 parent 0b019c5 commit 6744381

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Diff for: 04_objects.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Some objects
2+
// The 'key' can either be with quotes or not if its a single word
3+
var myDog = {
4+
name: 'flanagan',
5+
'the legs': 5,
6+
tails: 0,
7+
friends: ['j', 2]
8+
};
9+
10+
// Object access to properties
11+
var name = myDog.name;
12+
var legs = myDog['the legs'];
13+
14+
var property = 'friends';
15+
var friends = myDog[property];
16+
17+
// Modify properties
18+
myDog.name = 'Antonio'
19+
myDog.bark = 'woof'
20+
delete myDog.tails
21+
22+
// Check if property exists
23+
console.log(myDog.hasOwnProperty('tails'))
24+
25+
// Access complex objects
26+
var myPlants = [
27+
{
28+
type: "flowers",
29+
list: ["rose", "tulip", "dandelion"]
30+
},
31+
{
32+
type: "trees",
33+
list: ["fir", "pine", "birch"]
34+
}
35+
];
36+
var secondTree = myPlants[1].list[1];

Diff for: 05_loops.js

Whitespace-only changes.

0 commit comments

Comments
 (0)