I need to match any item within 2 array's and then return the value of that match. For example:
let arr1 = [ 'grid-view' ,'list-view' ];
let arr2 = [ 'test', 'list-view' ];
From the above I would get list-view
returned.
This is what I have at the moment, however it returns true, whereas I need the actual match. Trying avoid doing horrid big loops and having too much code.
let switches = document.querySelectorAll('[data-switch]');
let switchesClasses = [].slice.call(switches).map(x => x.dataset.switchClass);
const found = Array.from(document.querySelector('.test').classList).some(r => switchesClasses.includes(r));
console.log(found);
<div class="showroom-layout-toggle" data-switch-group="showroom_layout" data-switch-target=".test" data-switch-cookie>
<button class="grid-toggle" data-switch data-switch-class="grid-view">Grid</button>
<button class="grid-toggle" data-switch data-switch-class="list-view">List</button>
</div>
<div class="test list-view">Hello</div>