I know there has been a question like this, but mine is a little different, and it already works, but I don't know how to simplify it.
if (location.pathname === `/` || location.pathname ===`/kurikulum/` || location.pathname === `/pengembangan-diri/` || location.pathname === `/statistik/` || location.pathname === `/teknologi/` || location.pathname === `/ekonomi/` || location.pathname === `/desain/` || location.pathname === `/corona/`)
as you can see it is not beautiful, I wonder can we make it without repeating location.pathname?
this is on gatsby, but it is a javascript question
You can use Array.includes to check if the current pathname exists in a given array.
let pathArr = ['/', '/kurikulum/', '/pengembangan-diri/', '/statistik/', '/teknologi/', '/ekonomi/', '/desain/', '/corona/'];
let testPath = '/desain/';
if (pathArr.includes(testPath)) {
document.write('path found!');
};
Learn more about Array.includes here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With