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

300
Vistas
Using Map and Filter at the same time in JavaScript

I'm trying to use the map and filter example at:

https://masteringjs.io/tutorials/fundamentals/map-filter#:~:text=JavaScript%27s%20Array%23map%20%28%29%20and%20Array%23filter%20%28%29%20functions%20are,function%20works%20fine%20on%20an%20array%20of%20numbers.

var data = [
        {
            "pmid": 12637528,           
            "citation_count": 75
        },
        {
            "pmid": 12732634,          
            "citation_count": 49
        },
        {
            "pmid": 15118089,           
            "citation_count": 88
        }
]

I am using

let iIndex =  data.map(d => d.citation_count).filter( d.citation_count >=50);

and

 let iIndex =  data.map(d => d.citation_count).filter( data.citation_count >=50);

but I get the following error: "err = ReferenceError: d is not defined at eval" or with data.citation err = TypeError: false is not a function at Array.filter

If I take the .filter off it works fine, and I get an array of just the citation count. Can someone help with the correct syntax for the filter portion? I have searched stackOverflow but there are a lot of answers that are about 10 years old and I'm not sure what the most current direction has gone. I have even seen a mention of flatMap. Thanks for the help

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

0

It's unnecessary to have d.citation_count in filter:

let iIndex =  data.map(d => d.citation_count).filter( d => d >=50);
about 4 years ago · Juan Pablo Isaza Denunciar

0

The reason your code is failing is because filter expects a function that returns a boolean - you have provided it with an expression.

A simple fix to your code would be to wrap your expression in an anonymous function:

const result = data.map(item => item.citation_count).filter(count => count >= 50)

You could also just use reduce, which combines the effect of both the filter and map functions, making the code more efficient:

const data = [
    { pmid: 12637528, citation_count: 75 },
    { pmid: 12732634, citation_count: 49 },
    { pmid: 15118089, citation_count: 88 },
]

const result = data.reduce((result, { citation_count }) => {
  if (citation_count >= 50) {
    result.push(citation_count)
  }
  return result
}, [])

console.log(result)

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