Skip to content

Commit 00a0f6c

Browse files
committed
update objects basics
1 parent b70e9fb commit 00a0f6c

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

Objects/01_object_basics.js

+19-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
const person = {
2-
name: 'john doe',
3-
age: 25,
4-
married: true,
5-
siblings: ['anna', 'peter'],
6-
greet: function (name) {
7-
return `hello, my name is ${name}`;
8-
},
9-
sayHello(name) {
10-
console.log(`hello, my name is ${name}`);
1+
// create object
2+
const wiwa = {
3+
firstName: 'wiwa',
4+
lastName: 'dncode',
5+
married: false,
6+
skills: ['html', 'css', 'javascript', 'linux'],
7+
sayHi: function () {
8+
console.log(`hello....`);
119
},
1210
};
1311

14-
// acces obj u can use dot notation
15-
// console.log(person.name); //john doe
16-
// change name john doe be peter walker
17-
person.name = 'peter walker';
18-
// console.log(person.name);
19-
20-
// print all object
21-
// console.log(person);
22-
// access object with function parameter
23-
// console.log(person.greet('wiwa'));
24-
25-
//acces obj on array
26-
console.log(person.siblings[person.siblings.length - 1]);
27-
28-
// delete property
29-
let siblings = delete person.siblings;
30-
console.log(siblings); //true its succesfully for delete
31-
console.log(person);
12+
// *** For print use object dot notation
13+
console.log(wiwa.firstName); // wiwa
14+
console.log(`Hello ${wiwa.firstName} ${wiwa.lastName}`); //Hello wiwa dncode
15+
// *** Re-assign object
16+
wiwa.firstName = 'john';
17+
console.log(`Hello ${wiwa.firstName}`); //Hello john
18+
// *** print object with array
19+
console.log(wiwa.skills[0]); //html
20+
console.log(wiwa.skills); // [ 'html', 'css', 'javascript', 'linux' ]
21+
console.log(wiwa.skills.length); // 4 for knowing all sum on array
22+
console.log(wiwa.skills.length - 1); // 3 for knowing the last array

0 commit comments

Comments
 (0)