Marta’s label maker now runs in JavaScript. You ported the Python script, then finished order 1043’s label in Finish the Shipping Label. The label includes the remote-area surcharge, bringing postage to £7.70, and keeps the £18.50 price because the order isn’t a gift. The courier gets indented JSON with the address, phone, cover, parcels, and cleaned tags.
You can now build and inspect objects, look up postage, supply defaults, deduplicate tags, and read and write JSON. Keep these choices handy when porting your next dict-based script:
- Read values with dots for known keys, such as
order.id, and brackets for variable keys, such asRATES[country]. In an object literal,[HOME_COUNTRY]: 3.2uses the variable’s value as the key. - List keys, values, or pairs with
Object.keys(),Object.values(), orObject.entries(). Numeric object keys become strings. Choose aMapwhen numeric keys must stay numbers. - Deduplicate tags with
new Set(), check membership with.has(), and useObject.hasOwn()to check an object’s own keys. JavaScript’sinchecks properties, including inherited ones. - Parse order text with
JSON.parse(). BeforeJSON.stringify(label, null, 2), turn Sets into arrays with[...tags]so their members reach the label.
These choices keep the data’s meaning intact, from the postage lookup to the courier’s booking form.