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
Export the actual value of the variable inside the function

I need to export (for using variables in other scripts and other .js files) the actual value of a variable inside a function, how i can do that?

Global variables with zero values are set, they change their values inside functions, I need to export these values only after the function is executed.

the variables that need to be exported are commented out inside the function.

let numberOfTracks = null;
let tracks = '';
let musicid = null;
let dude = '';
let currentTrack = null;
let pathForTrack = '';

    const generateTracksBox = function () {
        for (let i = 1; i <= numberOfTracks; i++) {  
            $(`<div class="container card chartsCard" data-musicid="${i}">
                <img class="card-img-top" src="/AppMusic/assets/chartLogo/${i}.svg" alt="Card image cap"></img>
                <div class="card-body">
                    <h5 class="card-title">${tracks[i-1].split('-')[0]}</h5>
                    <p class="card-text">${tracks[i-1].split('-')[1]}</p>
                </div>
            </div`).appendTo('.charts');
        }
        const dude = $('.chartsCard'); 
        for (let i = 0; i < dude.length; i++) {    
            dude[i].onclick = function () {
                currentTrack = $(dude[i]).data('musicid'); //need to export
                location.href = "music/player.html";
            }
        }
    }
    
    const getTracksArray = function () {
            let xhr = new XMLHttpRequest();
            xhr.open('GET', `/AppMusic/assets/tracks`);
            xhr.responseType = 'text';
            xhr.onload = function () {
                const pathsForTracks = new RegExp('(?<=href="\)(.+?)(?=")', 'g');
                const nameOf = new RegExp('(?<=mp3">)(.+?)(?=.mp3)', 'g');
                numberOfTracks = xhr.response.match(nameOf).length; // need to export
                tracks = xhr.response.match(nameOf)
                generateTracksBox()
                pathForTrack = xhr.response.match(pathsForTracks) // need to export
            }
            xhr.send();
    }
about 4 years ago · Juan Pablo Isaza
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!