I am debugging a javascript application. Please, observe a snapshot of the watch window:
Note, that the properties are displayed in what appears a total mess. It is probably their natural order, but when there are lots of them it becomes really annoying. Is it possible to order them?
Thanks.
YES (but not always insertion order). Most Browsers iterate object properties as: Integer keys in ascending order (and strings like "1" that parse as ints) String keys, in insertion order (ES2015 guarantees this and all browsers comply)
Comparing JavaScript Object Keys to Arrays To illustrate that JavaScript object keys are not ordered, let's compare them to an array: a simple list of items in a specific order. JavaScript arrays have a defined order from index 0 to the last item in the list, and items added to the array using .
getOwnPropertyNames() The Object. getOwnPropertyNames() method returns an array of all properties (including non-enumerable properties except for those which use Symbol) found directly in a given object.
Just press 'Sort values alphabetically' button:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With