const columnDateIndex = [
{ path: "2023|Jan 2023" },
{ path: "2023|Feb 2023" },
{ path: "2023|Mar 2023" },
{ path: "2023|Apr 2023" },
{ path: "2023|May 2023" },
{ path: "2023|Jun 2023" },
{ path: "2023|Jul 2023" },
{ path: "2023|Aug 2023" },
{ path: "2023|Sep 2023" },
{ path: "2023|Oct 2023" },
{ path: "2023|Nov 2023" },
{ path: "2023|Dec 2023" },
{ path: "2024|Jan 2024" },
{ path: "2024|Feb 2024" },
{ path: "2024|Mar 2024" },
{ path: "2024|Apr 2024" },
{ path: "2024|May 2024" },
{ path: "2024|Jun 2024" },
{ path: "2024|Jul 2024" },
{ path: "2024|Aug 2024" },
{ path: "2024|Sep 2024" },
{ path: "2024|Oct 2024" },
{ path: "2024|Nov 2024" },
{ path: "2024|Dec 2024" },
];
const columnPath = "Williams|Bonus|2024|Feb 2024";
const result = columnDateIndex.find((column) => {
const re = new RegExp(`${column.path}$`);
return re.test(columnPath);
});
console.log(result);
Output:
{ path: ‘2024|Jan 2024’ }
Expected Output:
{ path: “2024|Feb 2024” }
I want to get the exact end match.