I am running Electron 4.0.6 and react-scripts
3.0.1, which, I believe, includes babel. I wrote this code:
const data = [1, 2, 3]
for( const idx in data ) console.log(idx)
Expected output is:
0
1
2
Actual output is:
0
1
2
peek
last
with the last two indices mapping to functions. I have a large program written using for/in
loops, and I am daunted by the possibility of putting in error checking in every one of my loops to make sure I'm not accidentally consuming a function index.
My questions:
- Why am I seeing this?
- How do I fix it?
Edit:
Thanks for everyone's input. To be clear, the program used to work until I reinstalled it on a new computer. I used to be able to use for/in
to iterate over only the non-default indices in an array. I'm not sure why I can't do that anymore, and I'm wondering what changed that made it work the way it does now. Do I need to install an older version of react-scripts
? Simply rewriting the whole program to use of
loops doesn't work, either, because I already do that when I can. I use for/in
loops when I need the index.
Edit 2:
I appreciate everybody's help. Thanks to the accepted answer, I was able to track down that the npm package dirty-json
is overriding all arrays with .peek
and .last
without setting them as non-enumerable. I am now able to address this issue.
Final edit: dirty-json
is fixed, so this exact problem should no longer occur. If you have arrived here because of a similar issue, check your packages; it is not dirty-json
as of version 0.9.0.