Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript get key of multidimensional array

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.

like image 350
Adola Avatar asked Feb 20 '23 18:02

Adola


1 Answers

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;
    }
}
like image 108
jeff Avatar answered Feb 24 '23 07:02

jeff