Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

444
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda