Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda