Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created August 28, 2012 16:31
Show Gist options
  • Save jpetto/3500066 to your computer and use it in GitHub Desktop.
Save jpetto/3500066 to your computer and use it in GitHub Desktop.
JavaScript object properties
var mj = {
first: 'Michael',
last: 'Jordan',
number: 23,
position: 'SG',
active: false
};
// get a property
console.log(mj.number);
// set a property
mj.number = 45;
// alternate get syntax
console.log(mj['number']);
// add a property
mj.titles = 6;
// add another property (alt syntax)
// BAD! DON'T DO THIS!
mj['career points'] = 32292;
console.log(mj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment