extract data from array in javascript

0

I have a function in ajax where I get data in the success

function editarUsuario(id_usu) {
    alert(id_usu);

        $.ajax({  
            url: "EditServlet",
            type: "GET",
            data: {
                id:id_usu
            },
            success: function (info_usu) {
                alert(info_usu);
            },
            error: function () {
                alert("no trae datos");
            }
        });
}

I put an alert to show info_usu

How do I get the name only? I hope you can help me.

    
asked by Javier fr 10.12.2017 в 00:49
source

1 answer

1

first you should know what kind of data you have in info_usu, it seems that it is an array, but to make sure you can do it by putting in the alert typeof (info_usu).

If it's an array, you just have to put the index that interests you in the alert.

alert(info_usu[1])

If it were a string, since the data is separated by ',' you could convert it into an array:

let datos = info_usu.split(',') alert(datos[1])

and then refer to the array element as I said above.

Greetings

    
answered by 10.12.2017 / 01:01
source