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

199
Views
Reaccionar mapa - valor de retorno

¿Cómo puedo devolver solo un elemento de una matriz de otro archivo donde el elemento (digamos que es "2" ) es igual a la identificación en ese archivo?

 import { AnotherFile } from './AnotherFile' const element = exFunc(element) const exFunc = (val) => { {AnotherFile.map((data) => data.id === parseInt(val) && return {data} )} }

Este es el otro archivo con datos:

 export const AnotherFile = [ { id: 1, text: 'Num 1', }, { id: 2, text: 'Num 2', }, { id: 3, text: 'Num 3', } ]

PD. Más exactamente, necesito un valor de "texto"

 alert("The text is: " + <>text value of data with id=2 from AnotherFile<>)
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

No funciona con && así en la función, necesitaría hacer un bloque lógico adecuado:

 const exFunc = (val) => { AnotherFile.map((data) => { if (data.id === parseInt(val)) return { data }; }); };
about 4 years ago · Juan Pablo Isaza Report

0

Puede intentar usar el método de filtro para esto. Tenga en cuenta el "?" operador para asegurarse de que no intenta acceder a un elemento que no existe

 const exFunc = (val) => AnotherFile.filter((v) => v.id === val)[0]?.text; console.log(exFunc(2));
about 4 years ago · Juan Pablo Isaza Report

0

Esta parte :

 data.id === parseInt(val) && return {data}

no trabaja dentro de una función

Prueba esto :

 if(data.id === parseInt(val)) return {data}
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!