Skip to content

Commit

Permalink
Idiomatic for...in for iterating over Object keys
Browse files Browse the repository at this point in the history
  • Loading branch information
SomajitDey committed Sep 22, 2024
1 parent 09541e7 commit 9e02b83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/bg-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@ function inbox(json){
}

data.Timestamp = Date();
const keysEnumArray = Object.keys(data); // Enumerated array of form fields.

// Create table row:
const row = document.createElement("tr");

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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 9e02b83

Please sign in to comment.