0 day streak
javascript / beginner
Snippet

Checking for Items with Array.includes()

The includes method determines whether an array includes a certain value among its entries, returning true or false. This is very useful for checking user roles or selected IDs in a Next.js application.

snippet.js
javascript
1
2
3
4
function checkPermission(roles) {
const isAdmin = roles.includes('admin');
return isAdmin;
}
nextjs
Breakdown
1
roles.includes('admin')
Checks if the string 'admin' exists anywhere inside the roles array.