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
javascript


source to share


No one has answered this question yet

See similar questions:

105
Is the Chrome JavaScript console lazy about evaluating arrays?
61
consolelog () async or sync?

or similar:

5722
How can I remove a property from a JavaScript object?
5101
What's the most efficient way to deeply clone an object in JavaScript?
3915
Why does Google add while (1); into your JSON responses?
3714
How to check if an array contains a value in JavaScript?
2709
Detecting object property undefined
2614
How do I change the class of an element using JavaScript?
2466
Sorting an array of objects by the value of the string property
2350
Storing objects in HTML5 localStorage
2284
How can I combine properties of two JavaScript objects dynamically?
1864
Iterating through object properties



All Articles
Loading...
X
Show
Funny
Dev
Pics