Read Json in js

1

I have the following arrays in php

$api = array( 
            'PlnDir' => $PlnDir,  
            'Agr' => $Agr, 
            'Emp' => $Emp,
            'Admin' => $Admin
        );

    $datos = array(  
            'menuPV' => $menuPrincipal,  
            'menuSH' => $menuSecundario, 
            'api' => $api
        );

$json = json_encode($datos);

In js I do the following

objJson = JSON.parse(json);

If I want to access the first variable 'menuPV' I do it in the following way

objJson.menuPV

How could I traverse the array api which in turn is an element of the data array from javascript?

    
asked by Lorenzo Martín 03.11.2018 в 00:18
source

1 answer

1

All you have to do is treat it as a simple javascript array:

for(var i = 0; i < objJson.api.length; i++ ){
    console.log(objJson.api[i].PlnDir);
}

I hope I have understood you well.

    
answered by 03.11.2018 / 00:42
source