'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}));
});


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jakub Kotrs