From 9e02b83e0213ecbd4ad44be29f088741581a0db9 Mon Sep 17 00:00:00 2001 From: Somajit Dey Date: Sun, 22 Sep 2024 23:04:12 +0530 Subject: [PATCH] Idiomatic for...in for iterating over Object keys --- app/bg-worker.js | 2 +- app/server.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/bg-worker.js b/app/bg-worker.js index 6f2799e..f669fb0 100644 --- a/app/bg-worker.js +++ b/app/bg-worker.js @@ -8,7 +8,7 @@ function urlEncoded2Json(str){ const obj = new Object(); - for (let el of arr) { + for (const el of arr) { let elArray = el.split('='); let val = decodeURIComponent(elArray[1].replace( /\+/g, ' ' )).replace(/"/g,'\\"'); // Decoded and escaped obj[elArray[0]]=val; diff --git a/app/server.js b/app/server.js index 23d9b67..5fa9c64 100644 --- a/app/server.js +++ b/app/server.js @@ -32,7 +32,6 @@ function inbox(json){ } data.Timestamp = Date(); - const keysEnumArray = Object.keys(data); // Enumerated array of form fields. // Create table row: const row = document.createElement("tr"); @@ -40,12 +39,12 @@ function inbox(json){ const header = document.getElementById("inboxHeader"); if (! numTotalMsgs) { header.replaceChildren();} - for (let key in keysEnumArray) { + for (const key in data) { // Create cell: const cell = document.createElement("td"); // Create a text entry: - entry = data[keysEnumArray[key]]; + entry = data[key]; // Append entry to cell: cell.append(entry); @@ -57,7 +56,7 @@ function inbox(json){ // Setup header according to the form fields. This is necessary as users may have custom form fields. // Create header block: const header_block = document.createElement("th"); - header_block.append(keysEnumArray[key]); + header_block.append(key); header.append(header_block); } }