var styles = ['btx btx1', 'btx btx2', 'btx btx3', 'btx btx4'];
$('#mst').on('click', function(){
let a = $('#btx').attr('class');
console.log(a); // `btx btx2`
let x = styles.findIndex(a);
console.log(x); // error
});
error - Uncaught TypeError: btx btx2 is not a function
I'm expecting 1 as the result
indexOfrather thanfindIndex, which expects a function parameter, as the error tells you. VTC as typo/resolved in a way unhelpful to future visitors.https://www.w3schools.com/jsref/jsref_findindex.aspfindIndex. You could do this withstyles.findIndex(e => e === a);but this is a more verbose and less efficient way to writestyles.indexOf(a).