简体   繁体   中英

Having issues creating a javascript object

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;

When you create an object you should use a colon not an equals sign.

eg

let myObj = {id: 1, value: 2}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM