Sorting Objects by Custom String ID Order in JavaScript

I have an array of objects, and each object has a string ID such as 135125-2024 or 513551-2024. I also have an array of IDs in a specific order, like string[]. I want to sort the array of objects based on this order of strings. What is the best way to do this using effective packages?

code example
if (res.notices) {
    let resArr: typeof res.notices = [];

    pubIds.forEach((pubId) => {
      let notice = res.notices!.find(
        (notice) => notice["publication-number"] === pubId,
      );

      if (notice) {
        resArr.push(notice);
      }
    });

    return {
      ok: true as const,
      data: resArr,
    };
  }
Was this page helpful?