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

122
Views
Prevent data from JSON from being the same as previous data

I'm developing a Chrome extension and I have a button. When this button is clicked, it gets a random URL from JSON. I don't want the last URL to be the same as the random URL currently received. How can I get random URL until the data is different?

Javascript

var music;
var lastMusic; // Suppose I got this data.

window.addEventListener("load",function() {
    fetch('***data.json', { 
    method: 'GET'
    })
    .then(function(response) { return response.json(); })
    .then(function(json) {
        try {
            if(json.last_version !== chrome.runtime.getManifest().version) {
                $id("new-update").style.display = "block";
            }
            music = json.musics[Math.floor(Math.random()*(json.musics.length + 1))].url;
        } catch (error) {}
    });
},false);

UPDATE

I solved problem but Chrome throws an error Uncaught TypeError: Cannot read properties of undefined (reading 'url')

var music;
var lastMusic;

window.addEventListener("load",function() {
    fetch('https://kortopal.github.io/data/11a/data.json', { 
    method: 'GET'
    })
    .then(function(response) { return response.json(); })
    .then(function(json) {
        try {
            var musicInterval;
            if(json.last_version !== chrome.runtime.getManifest().version) {
                $id("new-update").style.display = "block";
            }
            musicInterval = setInterval(function() {
                music = json.musics[Math.floor(Math.random()*(json.musics.length + 1))].url; // Error Line
                if(music !== lastMusic){
                    clearInterval(musicInterval);
                    lastMusic = music;
                    setStorage();
                    loadStorage();
                }
            }, 100);
        } catch (error) {}
    });
},false);
about 4 years ago · Santiago Trujillo
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!