-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.js
More file actions
30 lines (24 loc) · 806 Bytes
/
object.js
File metadata and controls
30 lines (24 loc) · 806 Bytes
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
// Object declaration
var maleOrFemale = "gender";
var myObject = { // Key: Value
name: "Acus", // "name": "Acus" is the same
age: 18,
address: "Viet nam",
[maleOrFemale]: true,
getName: function() { // Do not use () => {} to declare functions in an object
return this.name;
}
};
myObject.address = "Ho Chi Minh"; // Modify the key's value in the object
myObject.email = "acus@hotmai.com"; // Add a key with a value to the object
// Acess the object and keys in the object
console.log(myObject);
console.log(myObject.name);
console.log(myObject["name"]);
var myKey = "address";
console.log(myObject[myKey]);
// Delete the key in the object;
delete myObject.address;
console.log(myObject);
// Access the function in the object;
console.log(myObject.getName());