Test if an object property is enumerable.
var isEnumerableProperty = require( '@stdlib/utils/is-enumerable-property' );
Returns a boolean
indicating if a value
has an enumerable property
.
var value = {
'beep': 'boop'
};
var bool = isEnumerableProperty( value, 'beep' )
// returns true
bool = isEnumerableProperty( value, 'constructor' );
// returns false
-
In contrast to the native Object.prototype.propertyIsEnumerable, this function does not throw when provided
null
orundefined
. Instead, the function returnsfalse
.var bool = isEnumerableProperty( null, 'a' ); // returns false bool = isEnumerableProperty( undefined, 'a' ); // returns false
-
Value arguments other than
null
orundefined
are coerced toobjects
.var bool = isEnumerableProperty( 'beep', '1' ); // returns true
-
Property arguments are coerced to
strings
.var value = { 'null': false }; var bool = isEnumerableProperty( value, null ); // returns true value = { '[object Object]': false }; bool = isEnumerableProperty( value, {} ); // returns true
var isEnumerableProperty = require( '@stdlib/utils/is-enumerable-property' );
var bool = isEnumerableProperty( {'a':'b'}, 'a' );
// returns true
bool = isEnumerableProperty( ['a'], 0 );
// returns true
bool = isEnumerableProperty( ['a'], 'length' );
// returns false
bool = isEnumerableProperty( {}, 'prototype' );
// returns false
bool = isEnumerableProperty( {}, 'hasOwnProperty' );
// returns false
bool = isEnumerableProperty( null, 'a' );
// returns false
bool = isEnumerableProperty( undefined, 'a' );
// returns false
bool = isEnumerableProperty( {'null':false}, null );
// returns true
bool = isEnumerableProperty( {'[object Object]':false}, {} );
// returns true