Reputation: 73
I'm attempting to create a JavaScript array and add objects to that array. I'm looping through the fields in a page and creating an object to add to the array at that time (see code) but for some reason when creating a new object the whole page of javascript code stops working. Am I doing something wrong in creating the object? Should I be doing it differently?
When I remove the "FArray[i] = {}" code and the rest of the code in the page starts working again.
function SetFields()
{
var FArray = new Array(FieldSet.length);
for (var i = 0; i < FieldSet.length; i++)
{
FArray[i] = { ID = FieldSet[i].ID, Value = document.getElementById(FieldSet[i].ID).value };
}
alert(FArray.length);
}
var FieldSet;
Upvotes: -1
Views: 240
Reputation: 5342
When you create an object you should use a colon not an equals sign.
e.g.
let myObj = {id: 1, value: 2}
Upvotes: 4