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

188
Views
TypeError TypeError: Cannot read properties of undefined (reading 'length') for Twitter bot
// function to generate a random tweet tweet
function ranDom (arr) {
  var index = Math.floor(Math.random()*arr.length);
  return arr[index];
};

This is the code used

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

0

Works fine here:

function ranDom (arr) {
  return arr[Math.floor(Math.random()*arr.length)];
};

var items = [254, 45, 212, 365, 2543];
console.log(ranDom(items));

about 4 years ago · Juan Pablo Isaza Report

0

In general, you can add this line in the start of your function

if (arr === undefined){
    return DEFAULT_VALUE; \\define your default value for this case..
}

to handle this case.

But you need to investigate why your arr is undefined from the function call.

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!