Reputation: 173
Basically when I use:
imageObj.src = "data:image/webp;base64,data[2]";
It will give me an error.
However, when I console.log(data[2]) and then copy and paste whatever data[2] is into the code like this:
imageObj.src = "data:image/webp;base64,sampleexampleasfnakdjfbaksjbrwkaerhdhcoaunsf";
Everything works out. Please help me understand?
Upvotes: 1
Views: 8977
Reputation:
Javascript does not interpolate variables inside strings like some languages. If data[2] is a string, use string concatenation to add data[2] to the URI:
imageObj.src = "data:image/webp;base64,"+data[2];
Upvotes: 2