I working for get data from SAP via REST API and return to work with JSON in Javascript. I want to re-format the date object from type 2021-01-01 to 01/01/2021 .

SAP has the data type Date but after serialize to JSON format. SAP Date object has be convert to String data type.

My older code conversion in Javascript is

Code formatter version 1

In my source code version 1, I'm not happy for this because hard understand and source code not clarify. I will rewrite this.

Code formatter version 2

In my source code version 2, I'm first focus clarify in code. I using the destructuring assignment to get data from string split result and use the functional programming for build the new string format from array.


The technique from Code formatter version 2 you can adapt to other use case in string split because you can clarify array index after split string and re-formatter use the functional programming.