Access a property of a JSON

3

I have the following JSON

"values": [
        ["Martes", "pan", [8, [4],[0]], 7.381498329613434]
    ]
}

What would be the way to show the value: 7.381498329613434 in my Javascript console?

Thank you very much

    
asked by Isaac Alejandro 07.11.2018 в 23:00
source

2 answers

5

To access this value you must first access the object that contains it in this case values

    data={"values": [
            ["Martes", "pan", [8, [4],[0]], 7.381498329613434]
        ]
    }

    values = data.values;
    arr_values = values[0]
    console.log(arr_values[3]);

As you can set I assign to a variable called values the object that contains my desired value.

With this assignment I get an array:

To obtain the desired value, I only address the desired position in this case 3

arr_values[3]

and there you would have your result:

I hope it will help you and help you! !!

    
answered by 07.11.2018 / 23:15
source
4

You can do it like this:

var obj = {"values": [
        ["Martes", "pan", [8, [4],[0]], 7.381498329613434]
    ]
}

console.log(obj.values[0][3]);
    
answered by 07.11.2018 в 23:04