Si tengo una matriz como esta
["one","two","three","hello","world","bar"]¿Cómo encontraría qué objeto en la matriz es "Hola"?
const arr = ["one","two","three","hello","world","bar"]; const index = arr.indexOf("hello"); console.log(index)Podrías usar findIndex() o indexOf() . Ambos devuelven el índice del elemento si está en la matriz o -1 si no lo está.
const array = ["one","two","three","hello","world","bar"] const result = array.findIndex(item => item === "hello"); if(result === -1) console.log("Not found"); else console.log(`"hello" found at index ${result} in array: array[${result}] = ${array[result]}`); const array = ["one", "two", "three", "hello", "world", "bar"] const result = array.indexOf("hello"); if (result === -1) console.log("Not found"); else console.log(`"hello" found at index ${result} in array: array[${result}] = ${array[result]}`);