const arr2obj = (arr, reverse = false, isValid = (x) => { return true }) => {
let obj = {}
arr.forEach((v, i) => {
if (!(isValid(i))) return
reverse ? obj[v] = i : obj[i] = v
})
return obj
}
a = Array.from('abcdefg')
console.log(arr2obj(a, true, (x) => { return x % 2 !== 0 }))
To embed this project on your website, copy the following code and paste it into your website's HTML: