md`
## Structural Types
### Array
The JavaScript Array class is a global object that is used in the construction of arrays; which are high-level, list-like objects. Arrays cannot use strings as element indexes (as in an associative array) but must use integers.
Example:
\`\`\`JavaScript
//creating an array in JS
let fruits = ['Apple', 'Banana', 'cherry'];
// Apple
let first = fruits[0];
//3
console.log(fruits.length)
\`\`\`
Reference from [MDN Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
### Object
#### Define an Object
Objects can contain many values. It's similar to python's dictionary. The values are written as **name:value** pairs (seperating with a colon):
\`\`\`JavaScript
var person = {
firstName: "Edward",
lastName: "Johns",
age: 34
};
\`\`\`
#### Object Properties
The name:values pairs in JavaScript objects are called **properties**:
<img src="${await FileAttachment("image.png").url()}" style="width: 1000px;">
#### Accessing Properties
There are two ways of accessing the property:
* *objectName.propertyName*
* *objectName[propertyName]*
Choose the *dot property accessor* when the property name is known ahead of time. It will responds correctly when the property name is a proper identifier (An identifier in JavaScript contains Unicode letters, $, _, and digits 0..9, but cannot start with a digit.).
Choose to use the *square brackets property accessor* when the property name is determined at runtime, or when the identifier doesn't work for dot property accessor.
#### Object Methods
Objects can also have methods in them. Methods are stored in properties as function definitions.
Methods are functions stored as property.
<img src="${await FileAttachment("image@1.png").url()}" style="width: 1000px;">
Example:
\`\`\`JavaScript
var person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
\`\`\`
#### Accessing a Methods
An object method can be access with the following syntax:
* *objectName.methodName()*
If you access a method without the () parentheses, it will return the function definition.
Note: Try to avoid String, Number, and Boolean objects. They will slow down execution speed.
reference and pictures from:
[W3Schools JS Object](https://www.w3schools.com/js/js_objects.asp).
For difference between Javascript and Python:
[Python vs JavaScript for Pythonistas](https://realpython.com/python-vs-javascript/)
`