Javascript examples for Language Basics:Introduction
You can check to see if an object has a property using the in expression.
<!DOCTYPE HTML> <html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> var myData = {/*from ww w .ja v a2 s . c o m*/ name: "java2s.com", topic: "CSS", }; var hasName = "name" in myData; var hasDate = "date" in myData; document.writeln("HasName: " + hasName); document.writeln("HasDate: " + hasDate); </script> </body> </html>