How to get the view mode in js

I’d like to be able to determine the view mode, and I’ve seen threads and docs that talk about it, but I can’t seem to apply the information.

For context right now I want to do something simple – change a metabind icon based on the view mode, as generated by some dataviewjs.

What do I need to do to access this? thanks!

Somehow I managed to puzzle this out! Maybe it helps someone one day.

console.log(app.workspace.activeLeaf.getViewState().state.mode)