Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arrays in original target are mutated by library

See original GitHub issue

When you have this code

const item = { numbers: [1, 2] }

calling Object.keys(item.numbers) yields ['0', '1', '__length'] instead of just ['0', '1'].

This is due to the following change:

Expected: Original object should not be mutated.

Of course Object.keys() is not really useful on arrays, but it causes a strange error in jest saying serializes to the same string.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

BinarySpikecommented, Nov 7, 2021

I need to test this on my side—it may be an improvement for me. There are differences between the native proxy and the polyfill proxy when it comes to __length and in my client code I have to manually filter it out to support IE11 / polyfill. This might remove the need for my manual check.

I can see no downsides for my use-cases!

ElliotNBcommented, Feb 25, 2021

@MZanggl Excellent! I’ll get a PR opened up for it and get it published out on npm soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid mutations of objects while pushing them in an ...
At first it works when you generate the first book, but for some weird reason, when you do it a second time you...
Read more >
Object Mutation In JavaScript - Dev Genius
All primitives are immutable; that is, they cannot be altered. The variable may be reassigned to a new value, but the existing value...
Read more >
Washing your code: avoid mutation - Artem Sapegin
Mutations happen when we change a JavaScript object or array without creating a new variable or reassigning an existing one.
Read more >
Immutable Array Methods: Write Cleaner JavaScript Code
Arrays in JavaScript are just objects, which means they can be mutated. In fact, many of the built-in array methods will mutate the...
Read more >
Updating Arrays in State - React Docs
To do that, you can create a new array from the original array in your state by calling its non-mutating methods like filter()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found