Object.hasProperty >= 0.1.0

Purpose

See if a key exists in an object or array

Syntax

Object.hasProperty ( Objecttarget Stringproperty );

Parameters

target
property

Return values

Boolean

Examples

See if a property exists in an object

var obj = {
    a : 1,
    b : undefined
};

Object.hasProperty(obj, 'a');>>> true

// This is true, because property b has explicitly been set to undefined
Object.hasProperty(obj, 'b');>>> true

Object.hasProperty(obj, 'c');>>> false

See if a property exist in an array

var arr = [0, 1, 2, undefined];

Object.hasProperty(arr, 0);>>> true

// This will be true, because it's an explicit "undefined"
Object.hasProperty(arr, 3);>>> true