In JavaScript, you can use a for loop to target an element from an array. Here is an example:
let arr = [1, 2, 3, 4, 5];
for (let i = 0; i < arr.length; i++) {
if (arr[i] === 3) {
console.log("Found element: " + arr[i]);
break;
}
}
You can also use the forEach method to target an element from an array, example:
let arr = [1, 2, 3, 4, 5];
arr.forEach(function(element) {
if (element === 3) {
console.log("Found element: " + element);
}
});
or you can use the find method -
let arr = [1, 2, 3, 4, 5];
let result = arr.find(element => element === 3);
console.log(result);
In these examples, the loop iterates over each element of the array, and if the element is equal to 3, the loop will print "Found element: 3" and exit.