Loops
Tradicional Loop
Efficient but has too much info:
demo.js
const array = [2, 4, 5, 8];
const expected = 5;
let result = 0;
for (let index = 0; index < array.length; index++) {
const element = array[index];
if(element === expected){
result = element;
}
}
console.log("result", result); ${2}
Instead
You can make very shortened loop
const array = [2, 4, 5, 8];
const result = array.filter(item => item === 5);
console.log("result", result);