I have an object that is build with from an html form. When i fill the form I obtain this json object we call "jsonObjectForm" :
{
"inputID1": "content1",
"inputID2": "content2",
"inputID3": "content3",
"beginningDate": "2020-02-02",
"endingDate": "2022-03-03",
"inputID4": "content4",
"inputID5": "content5",
"inputID6": "content6",
"inputID7": "content7",
"inputID8": "content8"
}
I have a second object that i have to use to build a sql query. this object is
let fieldNames = {
"inputID1": "dbField1",
"inputID2": "dbField2",
"inputID3": "dbField3",
"inputID4": "dbField4",
"inputID5": "dbField5",
"inputID6": "dbField6",
"inputID7": "dbField7",
"inputID8": "dbField7",
};
I found the way to browse the first object. I defined the form elements i want to "scan" in the form :
const pageFormElements = getAllFormElements(document.getElementById("requestForm"));
for(let [key, value] of Object.entries(jsonObjectForm)) {
pageFormElements.forEach(element => {
console.log("key: " + key + " | value: " + value);
}
}
My question is how do i manage the double forEach in this case and I wonder if there's a way to "map" the values from the first object to the second and build a final object that would look like this:
let fieldNames = {
"dbField1": "content1",
"dbField2": "content2",
"dbField3": "content3",
"dbField4": "content4",
"dbField5": "content5",
"dbField6": "content6",
"dbField7": "content7",
"dbField7": "content8",
};
My objective is to create a query like this
query = select * from whatever where dbField1 = content1 AND dbField2 = content2 ... AND dbField8 = content8;