"in" Operator in Javascript Date: March 23, 2008  Tags: javascript    Comments(0)

Javascript 1.5 contains the in operator that checks only property names.I can't figure out why Javascript returns the exact opposite of that other programming languages return on this operator. Here is an example: >>> var hello = ["bonjour","hola","saluton","selam"]; >>> "bonjour" in hello false >>> 1 in hello true

Actually, we don't need to the in operator to check values of Array, we can use indexOf property to this action easily; >>> var hello = ["bonjour","hola","saluton","selam"]; >>> hello.indexOf("bonjour")>-1; true >>> hello.indexOf("Hallo")>-1; false

This operator available to checking object properties too but there are many way to check object properties already; >>> var hello = { "french":"bonjour", "esperanto":"saluton", "turkish":"selam" }; >>> "turkish" in hello true >>> "german" in hello false >>> Boolean(hello["turkish"]); true >>> Boolean(hello["german"]); false

The question is, how are object values checked?   


Leave Comment

Name:
E-Mail: (Will be not published)
Website:
 Your comment will be published after confirmation.

BROWSE BY TAGS

 appengine (1)  cherrypy (3)  comet (6)  debugging (1)  django (3)  greasemonkey (1)  javascript (11)  linux (3)  misc (11)  pi (5)  python (3)  security (1)  turbogears (2)  turkce (1)

ARCHIVES

August 2008
July 2008
May 2008
April 2008
March 2008

RECENT WORK

english-turkish translator
firebug lite
YAMLWriter
pi.debugger
gmCeviri
View All

FLICKR

View All

LINKS

Cloudo&Hakan Bilgin
Muhammed Daud
Serdar Meydanci
Ferruh Mavituna
CherryPy
Christian Wyglendowski
the spanner
john resig
eric's weblog
dustin diaz

A Django site.