How to loop through JSON array?

前端 未结 8 1633
鱼传尺愫
鱼传尺愫 2020-12-01 14:52

I have some JSON-code which has multiple objects in it:

[
    {
        \"MNGR_NAME\": \"Mark\",
        \"MGR_ID\": \"M44\",
        \"EMP_ID\": \"1849\"
           


        
8条回答
  •  -上瘾入骨i
    2020-12-01 15:41

    You could use jQuery's $.each:

        var exists = false;
    
        $.each(arr, function(index, obj){
           if(typeof(obj.MNGR_NAME) !== 'undefined'){
              exists = true;
              return false;
           }
        });
    
        alert('Does a manager exists? ' + exists);
    

    Returning false will break the each, so when one manager is encountered, the iteration will stop.

提交回复
热议问题