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

250
Vistas
JavaScript If statement ERROR - null is not an object (evaluating

I am using TagUI(js based automation tool) and javascript, and while writing code to extract information from the a string I receive a "null is not an object (evaluating 'd1.match(/(Internet provider)(.*)(<br/>)/ig)[0];'

Where d1 can contain a couple of fields that I want to extract as parameters if a certain field is not available I would like to replace it with "not applicable"

examples:

d1 = "<p>please create a new entry.</p> <p>Person's name: Tom Jones<br/> Company: some company <br/> address: street one <br/> Employee ID: 07092120 <br/></p> "
OR
d1 = "<p>please create a new entry.</p> <p>Person's name: Jon Tomes<br/> Company: some company2 <br/> address: street two <br/><br/> Internet provider: O2 <br/> Employee ID: 07092121 <br/></p>"

I have tried the following expressions with no luck

provider = d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0];
if (typeof ((d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0]) === 'object' && (d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0]) !== null)){provider=(d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0]);}else{provider="not applicable"; }
if (d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0] !== null){provider="not applicable";}else{provider = d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0];}
if (typeof (provider = d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0]) !== 'string'){provider="not applicable";}else{provider=d1.match(/(Internet provider)(.*)(<br\/>)/ig)[0]; }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

@VLAZ's comment did the trick:

If .match() doesn't match anything, the result is null. .match()[0] would throw an error in that case.

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