Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
Response.data how to get a single data value

Here is the code that im using to try get a single element out of the data.response of an api:

client.on("message", msg => {
  var axios = require("axios").default;

var options = {
  method: 'GET',
  url: 'https://dad-jokes.p.rapidapi.com/random/joke',
  headers: {
    'X-RapidAPI-Host': 'dad-jokes.p.rapidapi.com',
    'X-RapidAPI-Key': '0f787e5af5msh468814e0b585173p1cacafjsn7d774dfb44ff'
  }
};
  if(msg.content === "daddy"){
    axios.request(options).then(function (response) {

      console.log(response.data);
      let dataDad = response.body
        msg.channel.send(`${dataDad}`)
  })`

and here is the response that i get from the api:

{
  success: true,
  body: [
    {
      _id: '60dd3729df8a37528bc79b03',
      setup: 'How often do scientists check the table of elements?',
      punchline: 'Periodically',
      type: 'periodical',
      likes: [],
      author: [Object],
      approved: true,
      date: 1618108661,
      NSFW: false
    }
  ]
}

How do I use the "setup" from the response data in my code at msg.channel.send( "the "setup" ) ?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I believe, You need to do response.data.body[0].setup in order to get the first objects setup property

msg.channel.send(response.data.body[0].setup);
about 4 years ago · Juan Pablo Isaza Denunciar

0

response.data.body is an array of objects. So, if you want to access the first object in that array, you would use response.data.body[0] So, to get the .setup property from that object, you would use this:

msg.channel.send(response.data.body[0].setup);

That will get you the setup property from the first object in the response.data.body array.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda