I'm working on a dashboard app for my company and for that I want to get the status of a Project out of my mongo db database. the query works fine and for updating my list view I use some lines of Javascript in a js query. The problem is that I'm not able to access the last entry in my array of status. I tried it with pop(), slice(-1), [array.length - 1]
It seems that it is not possible to use a math operator, I'm super confused.
Can anybody help me?
Thanks in advance,
Flo
const project_data = query1.data.project_status;
let indexOf = project_data.length;
let idx = indexOf - 1;
let statusData = project_data[idx]
projectstatus.setValue(statusData.status)
A couple things to try here - for starters, setValue returns a promise, so try
await projectstatus.setValue(statusData.status)
If that doesn't fix it, confirm if you can/can't access the data, try adding console.log(statusData.status) before any of the setValue lines, and check the debug console to see if the expected value is there. Then you can narrow it down the part that might be causing the issue.
Debug console can be accessed in the bottom right of the browser window.
thanks for the fast reply!
ok thanks I'm totally new to JS so I changed this. But the problem is that I cannot access the last entry of my array. When I look into the variables there is the wrong or no data:
it gives me no or just the first entry. When I manually put in idx = 6 it works, but not idx = 7 - 1 it seems that it's not possible to calculate something with the math operator. but also pop() and slice(-1) does not give me the last entry.