tengo una matriz
const array = [[1, 2], [3, 3]]; arr.forEach(el => { if (el[0] === el[1]) {return true} })
No tiene sentido volver verdadero en un forEach
Supongo que te refieres a esto:
const testArr = arr => arr[0] === arr[arr.length-1]; // test first and last const array = [[1, 2], [3, 3]]; const testResults = array.map(el => testArr(el)); // map the results console.log(testResults) // filter: const same = array.filter(el => testArr(el)); // FIND the array that has same first and last console.log(same.flat())
Deberías every
las funciones
const arr = [[1, 2], [3, 3]]; const b = arr.every(el => el[0] === el[1]); console.log(b); // false
Esto debería obtener el resultado deseado. Simplemente cambie console.log(true) a lo que quiera hacer si son iguales. Esto funcionará en cualquier longitud de matriz.
const array = [ [1, 2], [3, 3], ]; array.forEach((el) => { if (el[0] === el[el.length - 1]) { console.log(true); } });