Is it possible to iterate over imported modules in javascript?

I have a common exported property, route, in all of my imported modules, which I would like to access dynamically, but cannot decide how to iterate over the list of imported modules. It can be done?

import User from '/components/user.js';
import Document from '/components/document.js';

var routes = [];
[array of imported modules].forEach(m => routes.push(m.route));

UPDATE:

So far I have tried the following and cannot find a list of modules on any of them

console.log(User.constructor);
console.log(Reflect.ownKeys(this));
console.log(Reflect.ownKeys(User));

Where should I look?

+4
source share
1 answer

The only way to do what I can think of would be to use eval () since there are no dynamic import statements in js.

Would I suggest using a different library? Take a look here: https://github.com/jojois74/recycle.js

, mod.prepare, .

0

Source: https://habr.com/ru/post/1686945/


All Articles