为什么对象的属性没有被改变?

时间:2014-11-11 14:10:08

标签: javascript

我有一个名为fillet_array的数组,它包含对象(目前只有一个对象,但这会在整个程序中发生变化)。这是Chrome中的输出:

0: Object
  cid: "9351"
  imgsrc: "1a4b1ebb4a31e2104ec1f2bab8539731"
  index: 0
  sku: "TD00060S0"
  width: 0.31

这是我的代码(此时请注意mattes_number_layers为2):

console.log(fillet_array);
  if ("undefined" !== typeof(fillet_array) && "undefined" !== typeof(fillet_array[mattes_number_layers - 2]))
  {
    console.log("mattes_number_layers - 2: " + (mattes_number_layers - 2)); //outputs 0
    console.log("mattes_number_layers - 1: " + (mattes_number_layers - 1)); //outputs 1
    console.log(fillet_array[mattes_number_layers - 2]); //outputs Object
    console.log(fillet_array[mattes_number_layers - 2].index); //outputs 0
    fillet_array[mattes_number_layers - 2]['index'] = (mattes_number_layers - 1);//switch index in fillet_array
  } 
  console.log(fillet_array);

我正在尝试将对象的索引属性从0更改为1,但我的代码似乎不起作用,因为当我再次输出fillet_array时,它与第一个相同。

编辑:这是创建圆角对象并将其添加到数组的代码。这是在上面的代码之前调用的。

var fillet = {};
fillet.index = index;
fillet.imgsrc = thumb;
fillet.width = width;
fillet.cid = cid;
fillet.sku = sku;

if (typeof(fillet_array) === "undefined")
{
  fillet_array = [];
}

fillet_array[index] = fillet; //For now index is 0

0 个答案:

没有答案
相关问题