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

Gabotronix's avatar

Issue sorting by date with lodash

Hi everybody, I'm trying to have a sorted list of items by data using lodash and vue moments, I'm using a computed property but for some reason this computed property named sortByUsedDate returns a number instead of a sorted array... it's returning 11 exactly.

This is my code:

sortByUsedDate: function(){

        let sortedCodes = _.orderBy(this.modalPayload.discountcodes, (code) => {
            return Vue.moment(code.usedDate).format('MDYYYY');
        }, ['desc']);

        let sortedWithoutUnused = _.remove(sortedCodes, function(code) {
            return code.isBought === 1;
        });

        let unusedCodes = _.filter(this.modalPayload.discountcodes, function(code){
            return code.isBought == 0;
        });

        let final = sortedWithoutUnused.push(unusedCodes);

        return final;
    }
0 likes
1 reply
bobbybouwmann's avatar

Shouldn't you return sortedWithoutUnused instead? I believe the push method returns the index of the pushed item. So that might explain why you get a number back

sortedWithoutUnused.push(unusedCodes);

return sortedWithoutUnused;

Please or to participate in this conversation.