Answer the question
In order to leave comments, you need to log in
Does the entire array with objects change in the array?
https://codepen.io/anon/pen/QQamjX
there is also a description in css
The task is to change timeStart to true at the specified time in an array of attr objects
, the time is indicated in time
and it turns out it changes in the entire array
here is an example->
it will work if on the 10th line
transfer an array to a direct one, but it doesn’t work for me an array from redax, I get
grafik.forEach((elem)=>{
elem.attr = [{"title":"Hamam", "time":"1 hour 30 minutes", "timeStart ":false, "free":true},{"title":"Sauna", "time":"1 hour 30 min", "timeStart":false, "free":true}]
})
Answer the question
In order to leave comments, you need to log in
You are passing a reference to the same array to all elements of the graffik array :
grafik.forEach(elem => {
elem.attr = attr;
});
grafik.forEach(elem => {
elem.attr = attr.map(el => ({ ...el }));
});
grafik.forEach(elem => {
elem.attr = attr.map(el => Object.assign({}, el));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question