there is another loop called 'for in' loop
this loop loops through the properties of a object
syntax:
for (var something in object){
do something
}
since the object is defined as key-value pair here
ex:
var obj = { a : 'd', b:'d'}; // a, b are keys and their values are d, d respectively
for ( var prop in obj){
console.log(prop);
} //////////here the o/p is a, b since the this loop is looping through the object keys
*** if we want to use the object value instead of the keys of the object. we can do
obj[prop]; // this is value of the key
*** !== this is not equal to operator
I wasted a lot of time yesterday night, today is a new day. And my impetus for completing this
training is gone. I have to try to fight my distractions as well as the loss of my determination. I still need to continue. I hope writing this blog shows that i hadn't left this training yet. So this is the first step towards regaining my lost impetus to complete this project and not sound facetious and to try to get back to the fastidious methods i employ while doing these kind of things.
*** once again to create an empty object example is below
var bob = {};
each piece of info we add in a object is known as property
ex:
var bob = {
age = 22
}; // here age is a property and 22 is the value of this property
to access a value of a property we use '.' dot notation
ex: var a = bob.age; //here we are accessing the value of age property
we can also access by this as well
var a = bob["age"];
Another way to create object is to use keyword 'new' . this method is known as creating an object using a constructor.
ex:
var bob = new Object();
this loop loops through the properties of a object
syntax:
for (var something in object){
do something
}
since the object is defined as key-value pair here
ex:
var obj = { a : 'd', b:'d'}; // a, b are keys and their values are d, d respectively
for ( var prop in obj){
console.log(prop);
} //////////here the o/p is a, b since the this loop is looping through the object keys
*** if we want to use the object value instead of the keys of the object. we can do
obj[prop]; // this is value of the key
*** !== this is not equal to operator
I wasted a lot of time yesterday night, today is a new day. And my impetus for completing this
training is gone. I have to try to fight my distractions as well as the loss of my determination. I still need to continue. I hope writing this blog shows that i hadn't left this training yet. So this is the first step towards regaining my lost impetus to complete this project and not sound facetious and to try to get back to the fastidious methods i employ while doing these kind of things.
*** once again to create an empty object example is below
var bob = {};
each piece of info we add in a object is known as property
ex:
var bob = {
age = 22
}; // here age is a property and 22 is the value of this property
to access a value of a property we use '.' dot notation
ex: var a = bob.age; //here we are accessing the value of age property
we can also access by this as well
var a = bob["age"];
Another way to create object is to use keyword 'new' . this method is known as creating an object using a constructor.
ex:
var bob = new Object();
No comments:
Post a Comment