1. Data type: object; it can also be thought of as a key/value store, like a dictionary. Can replace switch{case:case:} or if Else
For example:
Function Phoneticlookup (val) {
var result = "";
var lookup = {
Alpha: "Adams",
Bravo: "Boston",
Charlie: "Chicago",
Delta: "Denver",
Echo: "Easy",
Foxtrot: "Frank"
};
result = Lookup[val];
return result;
}
Phoneticlookup ("Charlie");
2. It is sometimes useful to check whether the properties of a given object exist or do not exist. We can use the object of the hasOwnProperty (propname) method to have the property name of a particular object;
For example:
var myObj = {
Gift: "Pony",
Pet: "Kitten",
Bed: "Sleigh"
};
function Checkobj (checkprop) {
if (Myobj.hasownproperty (Checkprop)) {
var result= "";
Result=myobj[checkprop];
return result;
}else{
Return "Not Found";
}
}
Checkobj ("house");
3. A magical way to store data is to use JSON:
This data structure can even be used as an element in an array, for example:
var mymusic = [
{
"Artist": "Billy Joel",
"title": "Piano Man",
"Release_year": 1973,
"Formats": [
"CS",
"8T",
"LP"],
"Gold": True
},//First array element
{
"Artist": "Billy Joel",
"title": "Piano Man",
"Release_year": 1973,
"Formats": [
"CS",
"8T",
"LP"],
"Gold": True
}//second element of the array
];
4. Provide two ways to access objects:
①
var mystorage = {
"Car": {
"Inside": {
"Glove box": "Maps",
"Passenger seat": "Crumbs"
},
"Outside": {
"Trunk": "Jack"
}
}
};
var gloveboxcontents =mystorage.car.inside["glove box"];
Ii:
var myplants = [
{
Type: "Flowers",
List: [
"Rose",
"Tulip",
"Dandelion"
]
},
{
Type: "Trees",
List: [
"Fir",
"Pine",
"Birch"
]
}
];
var secondtree =myplants[1].list[1];
6.parse is used to parse a JSON object from a string, such as:
7.stringify () is used to parse out a string from an object, such as:
8. In JavaScript, a common way to iterate through an array is to use a For loop:
9. The traversal of multidimensional arrays is often implemented in nested loops and is used in the same way as in JavaScript and overlays:
The 11.while loop is executed only when the condition is true, and once the condition is false, the execution is completed:
hasOwnProperty: is used to determine whether an object has a property or object that you give a name to. However, it is important to note that this method cannot check whether the object has this property in its prototype chain, and that the property must be a member of the object itself.
isprototypeof: is used to determine whether the object whose prototype chain is to be checked exists in the specified object instance, or True, otherwise returns false.
Example: An array name for an object [I]. Object properties, iterating through the objects in the array;
2016.9.1 JavaScript Introductory Five