question-mark
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.

Deep equal with sorted keys in an object.

See original GitHub issue

Is there a way to perform a deep equal to check if the keys are in a defined order? example:

let a = {
   a: 1,
   b: {
     a: {
        a: 1,
        b: 1
      }
    }
};

let b = {
  b: {
    a: {
      b: 1
      a: 1,
    }
  },
  a: 1
};

Here a is equal to b as they have the same properties. But since they are not in the given order, i would like for the test to fail.

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
keithamuscommented, Nov 22, 2017

I think deep.ordered.keys sounds like a fantastic assertion to add!

3reactions
keithamuscommented, Nov 14, 2017

@ancmikesmullin unfortunately this is no longer true. The ES6 and above specs specify that keys are ordered by creation order.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sort JavaScript object by key - Stack Overflow
Here's how you can sort an object by its keys/properties, alphabetically: ... according to the following rule: if two items compare as equal,...
Read more >
How to Compare 2 Objects in JavaScript | SamanthaMing.com
One quick way to compare if 2 objects have the same key value, is using JSON.stringify . ... Yup, the 2 ways also...
Read more >
How to Sort JavaScript Object by Key - W3docs
In this tutorial, we will share a very simple and functional method to sort an array of objects by key. Here is a...
Read more >
Arrays (Java Platform SE 7 ) - Oracle Help Center
This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays...
Read more >
Array vs Set vs Map vs Object — Real-time use cases in ...
There is no built-in method for the sorting of the objects, but ES6 offers some interesting built-in key-sorting during the creation of the...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found