Object.hasProperty >= 0.1.0

Purpose

See if a key exists in an object or array

Syntax

Object.hasProperty ( ObjecttargetStringproperty );

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

Comments

Reece

Do you have any tips for creating write-ups? That's where I constantly struggle as well as I just finish up staring empty display for very long time.

Roberto

I discovered your site from Google as well as I have to state it was a great find. Thanks!

Lorenzo

Have you ever had issues with your web host? I'm open for suggestions as my webhost is horrible right now.