-1

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

pilchard
  • 12,414
  • 5
  • 11
  • 23
  • why not use an object for the variables? it is better maintainable and well structured. – Nina Scholz Jan 27 '22 at 09:08
  • Sorry, this is not a free code writing service. You are expected to show a minimal effort and provide your coding attempt so we can help you spot what's wrong with it. Also, Nina is right, the output you want is clumsy and difficult to maintain. Instead of saying what you _think_ will solve your problem, you should state the problem itself. – Jeremy Thille Jan 27 '22 at 09:10

1 Answers1

0

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);
Vitaliy Rayets
  • 2,299
  • 1
  • 6
  • 12