Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda