Try to get property - Node.js Object

Node.js examples for Object:Property

Description

Try to get property

Demo Code


function tryGetProperty ( object /*, propertyName1, ... */ )
{
  for ( var i = 1; i < arguments.length; i += 1 )
  {/*  ww  w  .jav  a  2 s  .co m*/
    if ( object === undefined )
      return;
    var propertyName = arguments[ i ];
    object = object[ propertyName ];
  }
  return object;
}

Related Tutorials