Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
¿Cómo puedo mostrar los datos con un verdadero dentro del objeto?

Obtener la colección de usuarios de firestore:

 useEffect(() => { if (currentUser) { const unsubscribe = db .collection("users") .doc(uid) .onSnapshot((snapshot) => { const arr = []; arr.push({ ...snapshot.data(), }); setUsers(arr); console.log(JSON.stringify(arr)); }); return () => { unsubscribe(); }; } }, [currentUser]);

Esto es lo que se muestra donde console.log(JSON.stringify(arr)) ;

 [ { 1: { others: "books", items: { Item1: true, Item2: true } }, 2: { items: { Item3: true, Item2: true }, others: "books", }, displayName: Inigi, address: "US", }, ];

¿Cómo puedo mostrar esos items de esta manera?

  • Objeto 1
  • artículo2

Estos son los codigos pero tengo este error:

 {user["1"]?.items.map((index) => ( <li>{index.Item1}</li> ))}

el error:

TypeError: _user$.items.map no es una función

y con estos codigos no da error pero no muestra nada:

 {user["1"]?.items?.map?.((index) => ( <li>{index.Item1}</li> ))}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El mapa es una función de matriz y el tipo de sus datos es un objeto.

typeof usuario["1"]?.elementos == objeto

lo que significa que tienes que iterar el objeto con for...in o de la forma que quieras.

Ejemplo:

 const firestoreResponse = [ { 1: { others: "books", items: { Item1: true, Item2: true } }, 2: { items: { Item3: true, Item2: true }, others: "books", }, displayName: '', address: "US", }, ] //Destructure relevant data const obejctItems = firestoreResponse[0][1].items //Iterate the items object for(let item in obejctItems){ console.log(item) }

salida: Artículo1, Artículo2

about 4 years ago · Juan Pablo Isaza Report

0

Consideremos que tiene los siguientes datos:

 onst data = [ { 1: { others: "books", items: { Item1: true, Item2: true } }, 2: { items: { Item3: true, Item2: true }, others: "books", }, displayName: Inigi, address: "US", }, ];

puede acceder a cada usuario de la siguiente manera:

 const user1 = x[0][1]; const userItems1 = x[0][1].items;

y luego puede recorrer sus elementos y usarlos, por ejemplo, he creado una matriz de estos datos:

 let ar=[]; for (const [key, value] of Object.entries(userItems1)) { ar.push(value); console.log(`${key}: ${value}`); }

luego puede asignar esta matriz a cualquier componente como li .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!