We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

noah on 05/24/07


Tagged

object check test method property easy oo flanagan rhino complangjavascript


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

vali29


Does an object have a specific property?


Published in: JavaScript 


This is a very easy way to check if an object has a given property. Easier than checking if (obj.foo != null) or some such, which is what I've been doing :( From Flanagan, 5th ed, p. 108.; but I actually ran across it in the source of this page: http://www.gtalbot.org/DHTMLSection/DynamicOpacity.html, thanks to Gerard Talbot on clj.

  1. if ("foo" in myObject) {}

Report this snippet 

You need to login to post a comment.