1👍
✅
You can use Array of Objects for selected
and later create Object of Object when needed.
in Array, if you delete 2nd item, 3rd item will take 2nd item’s place and so on..
for ex:
const selectedArray = [{
val: 'one'
}, {
val: 'two'
}, {
val: 'three'
}];
// remove/close 2nd tab
let removedTab = 2;
selectedArray.splice(removedTab - 1, 1);
const selected = selectedArray.reduce((a, d, i) => {
a[`/machines/${i + 1}/home`] = d;
return a;
}, {});
console.log(selected)
Source:stackexchange.com