JQuery using "inarray" on a nested array to find a specific index of a value?

I am struggling with this, I am still new to javascript, and I am trying to use the jquery $ .inarray function as I need to find the value in the array so that I can return other values ​​from the same array as “string”, for example, its identifier.

When I try to use a jquery inarray function like this, I simply return -1, saying that it does not exist, when I know that the value exists, nested in an array. I'm not sure how to approach this, so that I can look for meaning, any advice is welcome.

valuereturn = $.inArray("search_for_value", jsonarray) ;
alert (valuereturn)

EDIT 2:

Here is the result of my cakephp JSON echo:

    {"getdata":[{"Uiemail":{"uiemail_id":"2","divid":"upd1","width":"200","height":"200","leftpos":"122","toppos":"122","cssgroup":"1","colortop":"","colorbottom":"","colorborder":"","borderwidth":"","zindex":""}},
{"Uiemail":{"uiemail_id":"3","divid":"upd2","width":"200","height":"200","leftpos":"333","toppos":"444","cssgroup":"1","colortop":"","colorbottom":"","colorborder":"","borderwidth":"","zindex":""}},
{"Uiemail":{"uiemail_id":"4","divid":"upd3","width":"200","height":"200","leftpos":"555","toppos":"466","cssgroup":"1","colortop":"","colorbottom":"","colorborder":"","borderwidth":"","zindex":""}}]} 

EDIT:

In addition, here is the conclusion:

alert(typeof jsonarray+'\n'+jsonarray.length)
output= "object 3 "

I tried this too, but it gives no value and makes errors on my page:

alert(jsonararray)
+3
2

, , .

  1. uiemail_id
  2. .
  3. , divid ""

:

function deepsearch ( blob, val ) { 
    var result = false;
    for( var item in blob ) {
        if( typeof blob[item] === 'object' ) {
            result = deepsearch( blob[item], val );
            if( result != false ) return result;
        } else if( blob[item] == val && item == 'uiemail_id' ) {
            // found item, blob = obj in which found
            result = blob.divid; // the divid from this "line"
            break; // assume first found wins            
        }
    }
    return result;
}      

JSON:

var arr = {"getdata":[{"Uiemail":...

uiemail_id of 4 divid of upd3:

deepsearch( arr, '4'); // returns upd3
deepsearch( arr, '3'); // returns upd2

, , , , , , , .

0

, javascript , , javascript. :

" PHP?

, , - , , javascript ( )

0

Source: https://habr.com/ru/post/1756361/


All Articles