[英]Having issues creating a javascript object
I'm attempting to create a JavaScript array and add objects to that array. 我正在尝试创建一个JavaScript数组并将对象添加到该数组。 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.
我遍历页面中的字段并创建了一个对象,以在当时添加到数组中(请参见代码),但是由于某种原因,当创建新对象时,整个javascript代码页面将停止工作。 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. 当我删除“ FArray [i] = {}”代码后,页面中的其余代码将重新开始工作。
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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.