Thursday, 15 January 2015

javascript - Do java script or jquery has a function like inArraykey? -



javascript - Do java script or jquery has a function like inArraykey? -

as far know jquery has function inarrary apply following

$.inarray(value, array); homecoming -1 if not in array

however, function apply value , not suitable multidimension array

eg . fruit [ apple,orange]

for instance, if have array this

eg. fruit [apple => [red,$1], orange => [orange,$5]]

i have check whether value exist (eg. banana) array key, there function appropriate in case?

arrays cannot have string keys in javascript. objects can.

if want see if object contains has key banana, can test isn't undefined:

if (myobject.banana != undefined) { }

... or utilize hasownproperty, may improve in cases when may have initialized property undefined:

if (myobject.hasownproperty("banana")) { }

javascript jquery arrays indexing

No comments:

Post a Comment