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

110
Vistas
How can I call another element from an array with the same name?

I'm relatively new to JavaScript / React.js. I have a random API from which I want to read an item (in this example an email adress).

What if the array has more emails for different users?

In that case, how can I call that specific email, let's say 2nd and 5th. What is the syntax for that?

Code is given bellow:

   import {useState,useEffect} from 'react';

function App(){

  const url = 'https://randomuser.me/api/';

  const [information,setInformation]=useState([]);
  
  async function getData(){
    const resp = await fetch(url);
    const data = await resp.json();
    console.log(data);
    const [item]=data.results;
    setInformation(item);
  }

  useEffect(()=>{
    getData();
  },[])

  return(
    <>
      {information.email}
    </>
  )
}
export default App;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since you are getting the data as an array, of the format

email: ["a@gmail.com", "b@gmail.com"]

You can map them as :

export default function App() {
  let information = { email: ["a@gmail.com", "b@gmail.com"] };
  return (
    <ul>
      {information.email.map((item, i) => (
        <li key={i}>{item}</li>
      ))}
    </ul>
  );
}

Or to display a particular email, say of 1st location, access them as:

   <>
      {information.email[1]}
    </>
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