I am trying to push data into array in this code
let eyesData = [];
const pushFaceData = (
{ rightEyeOpenProbability },
i
) => {
//Value is getting printed in console but not getting pushed
//console.log(rightEyeOpenProbability);
eyesData.push(rightEyeOpenProbability);
};
const renderFaces = () => {
faces.map(pushFaceData);
};
console.log(eyesData);
faces is stream of data that updates itself in every 100ms so eyesData array should also be getting populated on each 100ms but in console, eyesData is always getting printed with empty value.
Array[]
Array[]
.
.
mapon it. (That should beforEach, btw; you're not mapping anything.)eyesDatavariable, assigning[]to it, and then logging it, with no intervening call torenderFacesorpushFaceData. That's why it's empty. I suspect there's more to it in your real code, but we can only work with what you show us. Please update your question with a minimal reproducible example demonstrating the problem, ideally a runnable one using Stack Snippets (the[<>]toolbar button); here's how to do one.map()thing, but loop should run right. And data should be pushed intoeyesData. Right?if(!eyesData){eyesData=[]}eyesData.push(rightEyeOpenProbability);renderFaces, so it never callspushFaceData. But yes, ifrenderFaceswere called, it would work (That's why I think there's more to it and hope the OP provides that minimal reproducible example, so we can help.). It's just misleading semantically and creates and throws away an unnecessary array.