Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gabotronix's avatar

Lodash filter not working with multiple conditions

Hi everybody, I'm using lodash library to filter an array of objects but for some reason the filter it's returning the same value I pass to it, any idea what am I doing wrong?

This is the function I use to transform data:

getFlattenFields(schema)
    {
        let flatten = _.flatten(schema.fields);
        console.log('flatten',flatten);
        let filtered = _.filter(flatten, item => item.element != 'loader' || item.element != 'button' );
        console.log('filtered',filtered);
        return filtered;
    },

And my schema variable is this object:

formSchema: 
    {
        fields: 
        [
            [ 
                { id: 'email', label: '', default: '', element:'input', type: 'text' },
                { element: 'button', text:'Enviar', icon:'fas fa-reply' }, 
            ],
            [
                { element: 'loader' }, 
            ]
        ]
    }
0 likes
1 reply
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Shouldn't it be

item.element != 'loader' && item.element != 'button' );
1 like

Please or to participate in this conversation.