I have been looking and looking for a way to get a variable outside of a function. Here is a snippet of my code.
for (var i = 0; i < results.length; i++) {
var rawname = results[i].name
var name = encodeURIComponent(results[i].name)
var isdirectory = results[i].isDirectory
var filesize = '""'
//var modified = '10/13/15, 10:38:40 AM'
var modified = ''
var extension = name.split('.').pop();
// raw, urlencoded, isdirectory, size,
if (extension == 'mp3' || extension == 'flac') {
getEntryFile(results[i], function(file) {
jsmediatags.read(file, {
onSuccess: function(tag) {
var image = tag.tags.picture;
if (image) {
var base64String = "";
for (var i = 0; i < image.data.length; i++) {
base64String += String.fromCharCode(image.data[i]);
}
var base64 = "data:" + image.format + ";base64," +
window.btoa(base64String);
}
},
onError: function(error) {
console.log(error);
}
})
})
html.push(' {')
html.push(' name: "' + rawname + '",')
html.push(' artist: "' + rawname + '",')
html.push(' image: "' + base64 + '",')
html.push(' path: "' + name + '",')
html.push(' },')
}
}
I need to get the base64 variable ouside the 2 functions and use it in the html.push()
function.
Please DO NOT close this question. I have searched stack exchange for similar questions and they havent ever worked.
One method I tried was declaring a window variable using window.base64a = base64
but it just returned undefined. What can I do to get my variable outside the function?