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

115
Vistas
Check if JSON Object starts with 'https' in JavaScript

I have urls like this:

data:
{
  "zip": 442,
  "code": "AG",
  "capital": "london",
  "currency": {
    "code": "XCD",
    "name": "East"
    "link": "https://en.wikipedia.org/wiki/",
  "url": "https://en.wikipedia.org/"
  }

I want to write an if statement that checks if the object starts with a 'https:' and then tell it what to do.

This is what I have, but it doesn't make my urls clickable or returns its data.

if (jsonObject.startsWith("http://")) {
    const text = document.createElement("a");
    k.textContent = jsonObject;
    k.setAttribute("href", jsonObject);
    j.appendChild(k);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're close I believe, you just aren't accessing the actual values inside of the object.

If you want to check the Object's properties values and if they start with http/https you can loop through the object and use the same check.

jsonObject.values.forEach((value) => {
  if(value.startsWith("https://") {
    const text = document.createElement("a");
    k.textContent = value;
    k.setAttribute("href", value);
    j.appendChild(k);
  }
});
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