Is the hasOwnProperty method in JavaScript case sensitive? -


is hasownproperty() method case-sensitive? there other alternative case-insensitive version of hasownproperty?

yes, it's case sensitive (so obj.hasownproperty('x') !== obj.hasownproperty('x')) extend object prototype (some people call monkey patching):

object.prototype.hasownpropertyci = function(prop) {       return ( function(t) {          var ret = [];          (var l in t){              if (t.hasownproperty(l)){                  ret.push(l.tolowercase());              }          }          return ret;      } )(this)      .indexof(prop.tolowercase()) > -1; } 

more functional:

object.prototype.hasownpropertyci = function(prop) {    return object.keys(this)           .filter(function (v) {              return v.tolowercase() === prop.tolowercase();            }).length > 0; }; 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -