array_key_exists for javascript
Posted: Tue Nov 21, 2006 5:42 pm
Is there a function/method similar to array_key_exists or isset (for arrays) for javascript? I can't find one... 
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
if(document.forms['review'] != undefined){
// Do stuff
}No but this does the trick:The Ninja Space Goat wrote:Is there a function/method similar to array_key_exists or isset (for arrays) for javascript? I can't find one...
Code: Select all
Array.prototype.getKeys = function()
{
var ret = new Array();
for (var key in this) ret.psuh(key);
return ret;
}Code: Select all
var myArray = new Array();
myArray["x"] = 42;
myArray["y"] = 10;
var mykeys = myArray.getKeys();
alert(myKeys[0]); // "x"