I have array = ["Michael","Abraham", "Gabriel","Festus", "Ahab"]
how can I return elements in the array containing myValue = "ab"
which should be (Abraham,Gabriel,Ahab), I understand "indexOf" checks for the complete match.
Asked
Active
Viewed 59 times
0

otejiri
- 1,017
- 6
- 20
-
1What you have done so far ? hint: use `filter` and `includes` – Code Maniac Apr 03 '19 at 17:31
1 Answers
1
You can accomplish this using the filter method of array, please reference the code snippet below:
const array = ["Michael","Abigail","Gabriel","Festus", "Ahab"]
console.log(array.filter((name) => name.indexOf("ab") > -1));

etarhan
- 4,138
- 2
- 15
- 29