I am trying to map some items returned to me from a API using a class and constructor with javascript.
My question is what I am doing wrong, since the log before the mapping “Result before Map” logs out my array of items. But after my map I get nothing and everything in my constructor is undefined.
Im probably missing something simple but I am just trying this to do it without a framework using pure javascript in order to learn more 🙂
class Test {
constructor(obj) {
this.testValue = obj.testValue
}
}
async function getItems() {
const promises = []
const response = (await fetch(url)).json()
promises.push(response)
const result = await Promise.all(promises)
console.log('Result before Map:', result)
const tests = result.map(test => new Test(test))
console.log('Result after Map:', tests)
}