-2

I'm trying to import values of numbers from 1 to 20 to another js file [Index.js] here's my current code:

const what = {};

what. 1 = { number: 1 };
what. 2 = { number: 2};
what. 3 = { number: 3}

module.exports = what;

I have an error of: identifier expected is there a way to fix this error? so I can import the values to my other script? please let me know :)

JoonyBoy
  • 31
  • 7
  • 1
    Does this answer your question? [Object property name as number](https://stackoverflow.com/questions/16908476/object-property-name-as-number) – MrMythical Jan 31 '22 at 19:16

1 Answers1

1

Try to change your code like this:

module.exports = {
    1: { number: 1 },
    2: { number: 2 },
    3: { number: 3 },
};

You should then be able to access the properties with:

const obj = require('./path/to/file');
console.log(obj[1].number);
lpizzinidev
  • 12,741
  • 2
  • 10
  • 29