índice.js
const o = require('./altoken') for(const i=1; i<99; i++){ if(o.opts[i].identity.username === null){break;}; //error here message.guild.channels.create(o.opts[i].identity.username, {type: "text",parent: id}) }altoken.js
module.exports.opts1 = { mro: { as: false, }, identity: { username: "x", password: "x" }, krlo: [ 'x', ] };Quiero crear tantos canales como módulos en altoken.js pero recibo un error. TypeError: no se puede leer la propiedad '1' de indefinido
Desea acceder a una propiedad por nombre de propiedad dinámica. Necesita notación de corchetes:
o['opts' + i]Ejemplo:
const o = require('./altoken') for(const i=1; i<99; i++){ if(o['opts' + i].identity.username === null){break;}; //error here message.guild.channels.create(o['opts' + i].identity.username, {type: "text",parent: id}) }