can't we juste change it to:
`if (result[i].type && result[i].type.indexOf(type) != -1) {`