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

140
Vistas
Javascript Array.Filter method not working

im do not understand why this filter call is not working? it should be returning the one item that has the 100 dollar invoice but it is instead sending an empty set. What am i doing wrong?

const express = require('express');
const app = express();

app.listen(3000);
app.use(express.static('public'));
app.set('view engine', 'ejs');

const invoices = [
    {
        INVOICE_AMOUNT: 50
    },
    {
        INVOICE_AMOUNT: 100
    },
    {
        INVOICE_AMOUNT: 200
    }
];

app.get('/', (req, res) => {
    res.send(invoices.filter(x=>{x.INVOICE_AMOUNT==100}));
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The filter method needs a return value that is either truthy or falsy. If you return a truthy value, it keep the element, otherwise it filters it out.

Since you have no return statement nor you have an array function without parens, it always returns undefined and filters out all elements. Solutions are:

invoices.filter(x => { return x.INVOICE_AMOUNT == 100 })
// or
invoices.filter(x => x.INVOICE_AMOUNT == 100)

In the first case, there is an explicit return statement, in the second case, omitting the parens uses an implicit return statement.

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