How to find array of properties by data attribute JavaScript – best methods? or What’s the easiest wa

16 Replies, 1652 Views

Title: *How to find array of properties by data attribute JavaScript – best methods?*

Hey folks!

I’ve been scratching my head over how to find array of properties by data attribute javascript. Like, I need to grab all elements with a specific `data-*` attribute and store their values in an array.

I know `querySelectorAll` is a thing, but is it the *best* way? Or are there faster/more flexible methods? Maybe something with `getAttribute` or `dataset`?

Also, what if I wanna filter them further? Like, only get elements where `data-role="admin"`?

Kinda new to this, so any tips or code snippets would be awesome!

Thanks in advance! 🚀

Messages In This Thread
How to find array of properties by data attribute JavaScript – best methods? or What’s the easiest wa - by - 22-08-2024, 06:26 AM



Users browsing this thread: 1 Guest(s)