Will my experimental code function and behave in the same way as my working code, given that the HTML, CSS, and previous JS are functioning properly?
If not, what is causing the discrepancy? Additionally, how can I go about creating a loop-array style version of my code?
Experimental code:
var currentAccount = [];
var fieldList = ["firstName","lastName","age","gender"];
for (var i = 0; i < fieldList.length; i++) {
JSON.parse(fieldList[i]) = document.getElementById(fieldList[i]).value;
currentAccount.push(JSON.parse(fieldList[i]));
}
Working code:
var currentAccount = [];
var firstName, lastName, age, gender;
firstName = document.getElementById("firstName").value;
lastName = document.getElementById("lastName").value;
age = document.getElementById("age").value;
gender = document.getElementById("gender").value;
currentAccount = [firstName, lastName, age, gender];