extract the value of an element in an array with javascript

0

I have the following array

Array
(
    [inv_id] => 193
    [inv_prefix] => PREF
    [inv_number] => 192
    [inv_quotationNumber] => 0
    [inv_date] => 2018-04-09
    [inv_dateDue] => 2018-04-09
    [inv_empId] => 2
    [inv_cntId] => 304
    [inv_storage] => 1
    [inv_total] => 3200.00
    [inv_balance] => 3196.80
)

How can I get the value of the [inv_total] element with javascript?

    
asked by Juan Carlos 27.04.2018 в 22:16
source

1 answer

1

If you send it by PHP, what you have to do is format it to a json with the method of json_encode() , then on the javascript side you get it with, suppose it is called data , data.inv_total .

For example:

$array = array('inv_total' => 3200.00);
json_encode($array);

Then in javascript:

// acá iría tu ajax o fetch
var data = obtenerDatoDePHP();

console.log(data.inv_total);
    
answered by 27.04.2018 в 22:38