Compacting this repetitive JavaScript bit which trims values in an object
With single traversal on keys list and trimming all fields of type string:

Object.keys(shippingAddress).forEach((k) =&gt; {
    if (typeof shippingAddress[k] == 'string') {
        shippingAddress[k] = shippingAddress[k].trim();
    }
})