469,631 Members | 1,832 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

array_search() in Javascript?

hsriat
1,654 Expert 1GB
Is there any function in JS similar to array_search() of PHP which returns the key that contains the particular value, passed as argument. Or I need to make it myself?
Feb 16 '08 #1
2 10147
hsriat
1,654 Expert 1GB
Well, I guess there's not!


Expand|Select|Wrap|Line Numbers
  1. function arraySearch(arr,val) {
  2.     for (var i=0; i<arr.length; i++)
  3.     if (arr[i] == val)
  4.     return i;
  5.     return false;
  6. }
Feb 16 '08 #2
acoder
16,027 Expert Mod 8TB
If you want PHP equivalent functions, see this link. Your code is similar (though could do with some proper indentation).
Feb 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.