Answer the question
In order to leave comments, you need to log in
How to put the production of objects on stream?
There is a problem.
There is an array
let arr = [];
You need to constantly create a new object and insert it into the array.
let obj = {};
obj.word = 'qwerty';
arr.push(obj);
The problem is that when I insert an object multiple times, the array thinks that I am inserting the same object and updates the existing one.
The question is: how can you put the production of objects on a stream so that the newly created object is inserted as a new one, and not as an updated old one.
Answer the question
In order to leave comments, you need to log in
explain "permanently"
let arr = [];
for(i = 0; i < 1000; i++) {
let obj = {};
obj.word = 'qwerty: ' + Math.random();
arr.push(obj);
}
console.log(arr) // все разные
const Obj = function(word){
this.word = word
}
let objects = [];
for (let i = 0; i < 10; i++)
objects.push(new Obj(undefined))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question