HttpDo return string?

function click6(){
  if(dis==1){
    username = input.value();
    httpDo(
      userURL+username,
      {
        method: 'GET',
        // Other Request options, like special headers for apis
        headers: { Authorization: apikey},
        //mode: 'no-cors',
        datatype: "json"
      },
      function(res) {
        userinfo=res;
        console.log(userinfo);
        console.log(typeof userinfo);
        console.log(userinfo.level);
      }
    );
  }
}

This is my code to call an API and the console result is

Why is the type of userinfo is String? not JSON?
and whe the userinfo.level is undefined??

From the reference under HttpDo:

Method for executing an HTTP request. If data type is not specified, p5 will try to guess based on the URL, defaulting to text.

I suggest you provide the datatype when calling the function and see if this solves your issue.

The user info level is undefined probably because you dont have a json object in the first place. As soon as you solve the first issue, this one would work off the bat.

Kf