Skip to content

Instantly share code, notes, and snippets.

@dillonchanis
Last active March 7, 2018 18:50
Show Gist options
  • Save dillonchanis/7f581d8ac59528c8612db6ed1b9835bf to your computer and use it in GitHub Desktop.
Save dillonchanis/7f581d8ac59528c8612db6ed1b9835bf to your computer and use it in GitHub Desktop.
Deepfilter
function deepFilter (search, arr) {
if (!search) return arr
const result = []
arr.forEach(element => {
let temp = []
let found = false
Object.keys(element).forEach(k => {
if (String(element[k]).toLowerCase().includes(search.toLowerCase())) {
found = true
}
if (Array.isArray(element[k])) {
temp = deepFilter(search, element[k])
if (temp.length) {
found = true
}
}
if (found) {
result.push(element)
}
})
})
return [...new Set(result)]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment