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

152
Views
TypeError: Cannot read property 'forEach' of null

I try this code to check val in array2 is square in val array1, my code it works but i get error 'TypeError: Cannot read property 'forEach' of null'

let comp = (array1, array2) => {
  var index;
  if (array1.length === null && array2.length === null) return false;
  array2.forEach( (val) => {
    if (array1.includes(Math.sqrt(val))) {
      index = array1.indexOf(Math.sqrt(val));
      array1.splice(index, 1);
    }
  });
  return array1.length == 0 ? true : false;
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try adding this line at the top of the function:

let comp = (array1, array2) => {
    var index;
    if (array1 == null && array2 == null) return false;
    // Rest of the function
}
about 4 years ago · Juan Pablo Isaza Report

0

I guess instead of checking array2.length === null you should try array2.length === 0

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!