Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json Object fetch from javascript array

I have Json object like this

{
   "  resultArr": [
                   {
                     "ID":"1",
                      "0":"1",
                      "APPROVAL LEVEL":"1",
                      "1":"1",
                      "WorkFlow Type Code":"1",
                      "2":"1",
                      "Employee Number":"825489602V",
                      "3":"825489602V",
                      "Employee Name":"Wajira Wanigasekara",
                      "4":"Wajira Wanigasekara"
                     }
                 ]
}

i am trying to print the key and values of the resultArr.

for example, i want to print ID=1 APPROVAL LEVEL=1.. like that

i can get value of ID,APPROVAL LEVEL.. using this code

$.ajax({
                    type: "POST",
                    async:false,
                    url: "<?php echo url_for('workflow/getApprovalByModuleView') ?>",
                    data: { viewName: viewName },
                    dataType: "json",
                    success: function(data){

                        alert(data.resultArr[0][3]);
                    }
                });

but i want print the those names also...

that mean i want the print the KEY and VALUE of the data.resultArr array

how can i do that?

like image 353
Roshan Wijesena Avatar asked Dec 09 '25 20:12

Roshan Wijesena


1 Answers

Well you use key to select values. The only way I can think of is by looping trough them:

$.each(data.resultArr, function(index, value) { 
  alert(index + ': ' + value); 
});
like image 135
RJD22 Avatar answered Dec 11 '25 10:12

RJD22



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!