Why is the property of the object not changing?

I have an array called fillet_array that contains objects (currently there is only one object, but this changes throughout the program). This is the output in Chrome:

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

      

This is my code (note at this time mattes_number_layers

is 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);

      

I'm trying to change the index property of an object from 0 to 1, but the code I have doesn't seem to work because when I output again fillet_array

, it will be the same as the first one.

Edit: Here is the code creating a filet object and adding it to the array. This is called before the code above.

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

      

+3


source to share





All Articles