Tengo un proyecto JS/Svelte que obtiene algunos datos de un punto final de API interno. Puedo console.log() el valor que necesito pero no agregarlo a una matriz. Alguien puede ayudarme? Este es el código, este funciona perfectamente, devolviéndome la identificación que necesito:
let tracks = [] async function createTrack(name, artists) { const track_id = await fetch("/api/createtrack", { method: 'POST', body: JSON.stringify({ name: name, artists: artists, release: release._id }) }).then((response) => response.json()).then((data) => {return data.id;}); console.log(track_id) }pero esto no es así, no puedo agregar a la matriz:
let tracks = [] async function createTrack(name, artists) { const track_id = await fetch("/api/createtrack", { method: 'POST', body: JSON.stringify({ name: name, artists: artists, release: release._id }) }).then((response) => response.json()).then((data) => {return data.id;}); tracks.push(track_id) }