when result.index is -1 getByIndex
returns undefined
and getKeyValue
throws an error because it needs an object. The first argument of getKeyValue
should default to an empty object if getByIndex
returns undefined
, or just use an if else
statement instead of the nocode if
function