I have a JS/Svelte project fetching some data from an internal API endpoint. I can console.log() the value I need but not append it to an array. Can anybody help me? This is the code, this one works perfectly, giving me back the ID I need:
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)
}
but this doesn't, I can't append to the array:
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)
}