Difference between revisions of "Defining Objects"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
<pre> | <pre> | ||
var | 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)); | |||
</pre> | </pre> | ||
===Loop through items=== | ===Loop through items=== | ||
for(var item in | for(var item in john ){ | ||
console.log(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]);