I'm trying to add a key-value pair to an object in the array 'allIcos'. When I console log console.log(tgram) it's an array populated with floats but when I console.log(result) the telegram value is 'undefined' in all the objects in results. Where am i going wrong?
var allIcos = Object.assign(ico.results);
let tgram = []
var result = []
for (let i = 0; i < allIcos.length; i++) {
axios.get(`https://api.telegram.org/chat_id=@${tgramUrl[allIcos[i]}`)
.then(response => {
return tgram.push(response.data.result);
})
.catch(err => console.log(err));
}
console.log(tgram);
result = allIcos.map((o,i) => ({...o, telegram: tgram[i]}));
this.setState({data: allIcos});
console.log(result);
}