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

114
Views
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 answers
Answer question

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 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!