I'm working with javascript to return the username of users that are on a API and I can make it return something like this:
{"status":200,"users":[{"ID":2,"CreatedAt":"2022-04-24T16:17:41.615941Z","UpdatedAt":"2022-04-24T16:17:41.615941Z","DeletedAt":null,"alertTime":1,"sos":false,"username":"Jarret","access_mode":1,"UserFriends":null,"UserPositions":null},{"ID":3,"CreatedAt":"2022-04-24T16:17:44.203433Z","UpdatedAt":"2022-04-24T16:17:44.203433Z","DeletedAt":null,"alertTime":1,"sos":false,"username":"Narciso","access_mode":1,"UserFriends":null,"UserPositions":null},
And I want to return only the parameter called username
but it always return me undefined and I can't figure out why
Here's my code:
function showUsers() {
var myHeaders = new Headers();
myHeaders.append("Authorization", token);
var formdata = new FormData();
var requestOptions = {
method: "GET",
headers: myHeaders,
data: formdata,
redirect: "follow",
};
fetch("https://api.secureme.pt/api/v1/user/", requestOptions)
.then((response) => response.json())
//SPECIFING HERE VVVVV
.then((result) => document.getElementById("utilizadores").innerHTML = result.username)
.catch((error) => console.log("error", error));
}