'convert string '2018' to object obj2018 [duplicate]

I have list of

['2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025']

which i have to convert to different objects like

obj2018 = {}, obj2019 = {}, obj2020 = {}, obj2021 = {}, obj2022 = {}, obj2023 = {}, obj2024 = {}, obj2025 = {}. 

Can anyone help me please



Solution 1:[1]

You can create object with needed keys. Example:

const list =  ['2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025'];
let result = {};
for(const item of list){
  result[`obj${item}`] = {};
}
console.log(result);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vitaliy Rayets