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

16 Replies, 1609 Views

Hey! querySelectorAll is def a solid choice for how to find array of properties by data attribute javascript.

But if you wanna filter, just chain it with `filter()`:
```javascript
const elements = [...document.querySelectorAll('[data-role]')].filter(el => el.dataset.role === 'admin');
```

Also, check out MDN’s docs on dataset—super helpful for this stuff!

Messages In This Thread



Users browsing this thread: 1 Guest(s)