UNPKG

@x-govuk/govuk-eleventy-plugin

Version:

Write documentation using Markdown and publish it using GOV.UK styles

24 lines (21 loc) 553 B
/** * Select objects in array whose key includes a value * * @param {Array} array - Array to filter * @param {string} keyPath - Key to inspect * @param {string} value - Value key needs to include * @returns {Array} Filtered array */ export function includes(array, keyPath, value) { return array.filter((item) => { let data = item for (const key of keyPath.split('.')) { data = data[key] } // If data doesn’t exist, abort if (!data) { return false } return data.includes(value) ? item : false }) }