Object Methods & 'this'

hasOwnProperty

  • Object.hasOwnProperty('name-of-key');
  • Allows you to check an object for a specific key
  • Returns true/false

Example:

var obj = {
  kittens: 'aww';
};
obj.hasOwnProperty('kittens'); // true

Object.keys()

  • Object.keys(nameOfObject);
  • Returns an array of every key that an Object has

Example:

var obj = {
  kittens: 'aww',
  puppies: 'adorable'
};
Object.keys(obj); // ['kittens', 'puppies']

'this'

results matching ""

    No results matching ""