Programs & Examples
String Methods · Study material
An aligned invoice
padEnd and padStart with a dot filler produce a classic receipt layout; slice keeps long product names within the column and toLocaleString("en-IN") adds Indian digit grouping.
// padEnd / padStart build aligned columns; toLocaleString formats money in the Indian style
const items = [
["USB-C cable", 2, 349],
["Mechanical keyboard", 1, 4499],
["Mouse pad", 3, 199],
];
const line = (left, right) => left.padEnd(26, ".") + right.padStart(10, ".");
let total = 0;
console.log("INVOICE".padStart(21).padEnd(36) + "|");
for (const [name, qty, price] of items) {
const amount = qty * price;
total += amount;
console.log(line(`${name.slice(0, 20)} x${qty}`, amount.toLocaleString("en-IN")));
}
console.log(line("TOTAL", "₹" + total.toLocaleString("en-IN")));
INVOICE | USB-C cable x2...................698 Mechanical keyboard x1.........4,499 Mouse pad x3.....................597 TOTAL.........................₹5,794
Extracting order IDs
The match/matchAll example on the Introduction tab extracts IDs and statuses with named groups – a typical log-parsing task.