Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

251
Views
Node.js TypeError: Cannot read property '1' of undefined

index.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',
  ]
};

I want to create as many channels as modules in altoken.js but I am getting an error. TypeError: Cannot read property '1' of undefined

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You want to access a property by dynamic property name. You need bracket notation:

o['opts' + i]

Example:

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})
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!