Assign an array value to a variable

Good afternoon.
I have a problem with the arrangement that the only thing it has is a user id, the fix is ​​filled from BD, and it brings me the data and shows them, but at the time that in the promise I want to assign that value to a variable it tells me [object object] and I do not know how to do it.
What I’m trying to do is to assign the value that comes within the array to a variable, I tried to add it directly from the id_costumer but it says [object object] or indefinite

my services

public function idUsuarioRegistrado_get ( $token = 0 ) {
    
	//Petición a BD
	$queryidUser = $this->db->query('SELECT c.id_customer from ps_customer c where c.token = "'.$token.'" group by c.id_customer limit 1');
	
	//Manejo de errores
	$respuesta = array(
			'error' => FALSE, 
			'idUsuarioObtenido' => $queryidUser->result_array()
	);

	$this->response ( $respuesta );

}

my code

idUsuarioRegistrado( token:string ){
let promesa = new Promise ( (resolve, reject)=>{
let url = URL_SERVICIOS + “registro/idUsuarioRegistrado/” + token; //Obtengo el url

//Peticion del servicio
this.http.get( url ).subscribe ( res => {
  //console.log(res);
  if ( res['error'] ) {
    //Aquí tenemos un error
  }
  else{
    this.idUsuarioObtenido = res['idUsuarioObtenido'];
    this.id_usuario = this.idUsuarioObtenido[0]; //Grabo el usuario
    console.log( this.id_usuario );
    this.logProv.guadarStorage();
  }
})  
resolve();

})
return promesa;
}

Thanks in advance

I hope you can help me since the truth is I’m relatively new in this
regards

My advice is that you throw away whatever resource gave you the inspiration for this code and start completely over using the Angular HttpClient documentation as a guide.

That’s because, since the code is working well, the only thing I need to know is how to assign to the variable what comes within the arrangement, the arrangement does not come empty and the service works well, if I go through the arrangement and show it in screen does it well, the only thing is that I do not know how to grab that value to a variable

The mods don’t think it is appropriate for me to insist on talking about broader code quality issues when somebody is asking a specific question, so I’ve said my piece and am done with this thread.

1 Like