avatar
order and filter JavaScript arrays Javascript

To get a list from array b that follows the order specified in array a and includes the id and title properties, you can use JavaScript. Here's how you can achieve that:

let a = [131, 134];

let b = [
    {
        "id": 131,
        "title": "Laravel Dashboard With VueJs Framework",
        // ... other properties
    },
    {
        "id": 132,
        "title": "Setup Hosting Provider and Domain Settings",
        // ... other properties
    },
    {
        "id": 134,
        "title": "Filter the items in array b based on the order in array",
        // ... other properties
    }
];

// Filter the items in array b based on the order in array a
let result = a.map(id => {
    let item = b.find(item => item.id === id);
    return { id: item.id, title: item.title };
});

console.log(result);
24
query list of user and filter cognito in lambda function filter list on search input change Javascript filter array of objects by property value
You need to login to do this manipulation!