Difference between revisions of "Defining Objects"

From rbachwiki
Jump to navigation Jump to search
Line 1: Line 1:
<pre>
<pre>
  var comptype = {
  var john = {
brand: 'ibm',
    name: 'John',
ram: '128 Gigs',
    lastName: 'Smith',
hdrive: '1 Terabyte'
    yearOfBirth: 1990,
    job: 'Teacher',
    isMarried: false,
    family: ['jane', 'mark'],
    calculateAge: function(yob) {
        return 2016 - yob;
    }
};


}
console.log(john.calculateAge(1990));
</pre>
</pre>
===Loop through items===
===Loop through items===
  for(var item in comptype){
  for(var item in john ){
  console.log(item + " - " + comptype[item]);
  console.log(item + " - " + john [item]);
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Java Script|Category]]==
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Java Script|Category]]==

Revision as of 23:45, 1 November 2016

 var john = {
    name: 'John',
    lastName: 'Smith',
    yearOfBirth: 1990,
    job: 'Teacher',
    isMarried: false,
    family: ['jane', 'mark'],
    calculateAge: function(yob) {
        return 2016 - yob;
    }
};

console.log(john.calculateAge(1990));

Loop through items

for(var item in john ){
console.log(item + " - " + john [item]);

Back To Top- Home - Category