I have an array of objects:
var conversions = [
{ regex: ..., names: [ ... ] },
...
];
I loop through each conversion object and pass them to a certain function:
conversions.forEach(function(conv) {
// function selection logic
var result = func(message, conv); // func is the selected function, message is defined before
// result logic
}
The loop works fine for all the objects in the array, but after the last object, a weird object is passed to the callback which is not part of my array. Adding console.log(conv);
at the very beginning of the callback prints out all the conversions correctly, but the last weird object is printed out as epäluku undefined
. "Epäluku" is a bad Finnish translation for NaN
, which means the output is the same as NaN.toLocaleString() + " " + undefined
.
I haven't been able to figure out why this odd object is there, or how to filter it. I've tried checking it against null
and undefined
but neither did the trick. I've even tried checking it against NaN.toLocaleString() + " " + undefined
but that didn't work either.
This is part of a userscript, running in Chrome using Tampermonkey.