Unexpected Behavior When Trying to Sort a 2D Array of Objects by Nested Property in JavaScript
I'm encountering an issue while trying to sort a 2D array of objects based on a nested property. The array looks like this: ```javascript const data = [ [{ id: 3, name: 'Alice', details: { age: 25 } }, { id: 1, name: 'Bob', details: { age: 30 } }], [{ id: 2, name: 'Charlie', details: { age: 20 } }, { id: 4, name: 'David', details: { age: 35 } }] ]; ``` I want to sort the inner arrays based on the `age` property within the `details` object, but when I run my sort function, I see unexpected behavior where the order doesn't change as anticipated. Hereโs the sorting function Iโm using: ```javascript const sortedData = data.map(innerArray => { return innerArray.sort((a, b) => a.details.age - b.details.age); }); ``` My expectation is that the first inner array will be sorted to `[{ id: 1, name: 'Bob', details: { age: 30 } }, { id: 3, name: 'Alice', details: { age: 25 } }]` and the second inner array to `[{ id: 2, name: 'Charlie', details: { age: 20 } }, { id: 4, name: 'David', details: { age: 35 } }]`. However, it seems that the sorting is not functioning correctly for the first inner array. Iโve logged the output and noticed that the original order is preserved. I'm using Node.js version 14 and Iโve ensured my data structure is consistent. I've also tried using `console.log` to verify the values being compared in the sort function. It's as if the sorting logic is being ignored. Could this be happening due to how JavaScript handles sorting or is there something I'm overlooking? Any insights would be greatly appreciated!