4

I've the following array:

$test[$iterator][1][2]['name']

I have a function that needs to get $iterator of that array when ['name'] == 'value';

So how can I use Javascript to get the given $iterator?

Also, I did look at other questions, but I'm not sure if their answers apply to my question.

1
  • PHP or JavaScript? The $ seems a little strange. Commented Jul 22, 2012 at 18:39

1 Answer 1

8

Are you looking for something like this?

var $iterator;
for (var i = 0; i < $test.length; i++) {
    if ($test[i][1][2]['name'] == 'value')
    {
        $iterator = i;
        break;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is what I was looking for. I was trying some jQuery.methods, and they weren't working. Thanks alot! Also, yeah, I have a bad habit about sometimes using php variable names in my javascript code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.