Message from JavaScript discussions

July 2017

— var combined = Object.assign({}, obj1, obj2);


If obj1 has a prop like hello, and obj2 does too, then the prop in obj2 will override (not overwrite, obj1 will remain the same) that prop in the new object

— Basically arg 1 is a target object, which is what will be mutated directly

— Can you order it for me please

— Erm, well a JSON array is naturally ordered

— You can maybe order it in a way of your choosing by using Object.entries(obj)

— So something like
var myArray = Object.entries(obj).sort(compareFunction);

— What kind of order do you want, alphabetical?

— I want the created date to come out I descending order

— With that code at the moment its coming out randoming

— Hm, well items is an array, is it not sorting already?

— I mean looking at the query string there's &sort=created&order=desc which makes me think it at least should be doing that

Message permanent page