Sorting an array of objects by property values and change property values at same time

Viewed 17

i want to change trending position based on views if there is any way to do this via sort function in node js.

    var data = [
    {
    trending:1,
    views:10
    },
    {
    trending:2,
    views:20
    },{
    trending:3,
    views:30
    },
    ]
data.sort((a, b) => b.views - a.views)

sort function only change the order but i want to change trending position when sorting.

0 Answers
Related