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

119
Visualizações
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
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