I am solving a question of JavaScript by using find method. I want to find the first and all elements of array that contain letter ‘e’.
const fruits = ['apple', 'banana', 'cherry', 'dates', 'fig']
How I solve:
const res = words.find((alpha) => alpha == words)
2
Answers
Do you want all the elements or just the first? If you want all, you can use Array.filter. If you want just the first you can use find.
You can try this:
.filter() will return all the that elements match the condition passed. The original array won’t be modified.
.includes() will return true if the string contains the string passed to the function.