forked from benlcollins/introductionToAppsScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path011_IntroToAppsScript_Objects.js
More file actions
39 lines (29 loc) · 913 Bytes
/
Copy path011_IntroToAppsScript_Objects.js
File metadata and controls
39 lines (29 loc) · 913 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
31
32
33
34
35
36
37
38
39
// Objects
function objectFunction() {
// create with curly brackets
const obj = {};
// objects consist of key/value pairs
// ordering is not important
// often have line breaks to make easier to read
const employee = {
name: 'Joe Bloggs',
age: 25,
title: 'Data Analyst'
}
console.log(employee);
console.log(typeof employee);
// accessing values inside objects
console.log(employee.name); // dot notation
console.log(employee['age']); // square bracket notation
console.log(employee.title);
console.log(employee.height); // undefined because there is no height property in object
// add item to object
employee.favoriteFood = 'Fish & Chips';
employee['department'] = 'Marketing';
// or update values
employee.age = 26;
console.log(employee);
// delete an item from object
delete employee.favoriteFood;
console.log(employee);
}