'How to iterate the formData with for loop?
It is simple that i want to iterate formData with js.
An example to iterate the formData object located here.
to iterate formData in msdn
I create my iterate way according to the sample code.
function show()
{
var formData = new FormData( document.querySelector("#myForm") );
for(var pair in formData.entries())
{
console.log(pair[0]);
console.log(pair[1]);
}
}
ob = document.getElementById("submit");
ob.addEventListener("click",show);
<form id="myForm">
<input type="text" name="name">
<input type="text" name="addr">
<input type="button" value="submit" id="submit">
</form>
To type test1 in the first input and test2 in the second input,then click submit button.
The expect output in chorme's console
name
test1
addr
test2
The actual output in chrome's console.
n
e
How to fix my code to iterate the formData with for loop?
Solution 1:[1]
const formData = new FormData();
formData.append('screen', false);
formData.append('animation', false);
for (let [key, val] of formData.entries()) {
console.log(key, val);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MD SHAYON |
