JavaScript Arrays:
Reference:
W3 School JS
https://www.w3schools.com/js/js_arrays.asp
W3 School React JS
https://www.w3schools.com/react/default.asp
Example 1:
const cars = [
"Saab",
"Volvo",
"BMW"
];
Example 2:
const cars = [];
cars[0]= "Saab";
cars[1]= "Volvo";
cars[2]= "BMW";
or
let cars = []; //variables defined with let/const
cannot be Redeclared.
//Variables defined with let/const
have Block Scope.
for example
{
let x = 2;
}
// x can NOT be used outside the scope
or
var cars = [];
JavaScript Associate Arrays/object
Reference:
https://flexiple.com/associative-array-javascript/
Example 1:
var arr = {key1:'value1', key2:'value2'};
access object properties:
arr.key1 or arr['key1']
Example 2:
var arr = {
"Company Name": 'Flexiple',
"ID": 123
};
for (var key in arr) {
var value = arr[key];
document.write(key + " = " + value + '
');
}
//Output:
Company Name = Flexiple
ID = 123
No comments:
Post a Comment