April 28, 2019
Javascript Challenge #8: Filter by Starting & Ending of String
This is another javascript challenge where we will filter array by starting and ending word. I hope you will enjoy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
const myArray = [ 'Blue Sky', 'light green', 'dark Green', 'Blue Van' ]; function getStartswith(wordsArray, word) { return wordsArray.filter(myword => myword.toLowerCase().startsWith(word)); } function getEndswith(wordsArray, word) { return wordsArray.filter(myword => myword.toLowerCase().endsWith(word)); } const result = getStartswith(myArray, 'blue'); console.log(result); |