sorry for my bad English. I have weird problem when insert object to array then access it again.
Here is my code:
let content = new Array()
let dataDefault = {
frame: 0,
time_running: 0,
status: 'not_available',
precast_id: ['', ''],
product_type: ['', ''],
project: ['', ''],
mold_number: -1,
weight: {
ra: -1,
ri: -1
},
batch_id: [],
start: 0,
stop: 0,
code: ['', ''],
mix_design: ['', ''],
operator: '',
note: '',
auto: false,
quality: ''
}
for (let i = 0; i < 2; i++) {
content[i] = dataDefault
content[i].frame = i // it should be 0, and 1 <<--------------
}
// result content.frame = 1 in array [0, 1]
console.log(content)
I insert object into content array, then edit "frame" collection. It should be each array has different number of frame because of for loop. But I've got the same result on frame collection.
Here is the result:
[ { frame: 1, // <<-------------------- same
time_running: 0,
status: 'not_available',
precast_id: [ '', '' ],
product_type: [ '', '' ],
project: [ '', '' ],
mold_number: -1,
weight: { ra: -1, ri: -1 },
batch_id: [],
start: 0,
stop: 0,
code: [ '', '' ],
mix_design: [ '', '' ],
operator: '',
note: '',
auto: false,
quality: '' },
{ frame: 1, // <<-------------------- same
time_running: 0,
status: 'not_available',
precast_id: [ '', '' ],
product_type: [ '', '' ],
project: [ '', '' ],
mold_number: -1,
weight: { ra: -1, ri: -1 },
batch_id: [],
start: 0,
stop: 0,
code: [ '', '' ],
mix_design: [ '', '' ],
operator: '',
note: '',
auto: false,
quality: '' } ]
Where I did wrong? Hope you guys can help me, Thank you in advance.