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

431
Views
Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method

i'm using react native with regex

if i use my code

this error occured

Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method.

I want to put an empty value like ' ' in the match if any character other than a number and decimal point is included in my regular expression. If you put "123abc" in the value variable, match returns "123", but if you put "acv" in the value constant, the above error occurs. In this case, how can I put an empty string into the match without generating an error?

 const regex = /\d+(\.\d{1,2})?/;

const value = "abd"
const [match] = regex.exec(value);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can use || operator. in case exec return null it will default to empty string ''.

function getStrings(value) {
  const regex = /\d+(\.\d{1,2})?/;
  const [match] = [regex.exec(value) || ''];
  if(Array.isArray(match))
    return match[0]
  return match
}

console.log(getStrings("abd"))
console.log(getStrings("123abd"))

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!