Extract keys of an object - Node.js Object

Node.js examples for Object:Property

Description

Extract keys of an object

Demo Code

/**/*from  ww  w  . j  a v a  2s .  co m*/
 * Extract keys of an object
 *
 * Parameters:
 * (object) obj
 * 
 * Returns:
 * (Array) array with all key of the object
 */
function keys(obj){
  var keys = [];
  for(var key in obj){
    if(obj.hasOwnProperty(key)){
      keys.push(key);
    }
  }
  return keys;
}

Related Tutorials