JavaScript Demo: Array.filter()

JavaScript Demo: Array.filter()
0.0 0

#1

var words = [‘spray’, ‘limit’, ‘elite’, ‘exuberant’, ‘destruction’, ‘present’];

const result = words.filter(word => word.length > 6);

console.log(result);
// expected output: Array [“exuberant”, “destruction”, “present”]

  • Does the first letter start at of any object/ word in an array start at 0? how to access individual letters in the words in the array.

#2

you can use charat function to access characters. see more here:
https://www.w3schools.com/jsref/jsref_charat.asp

just remember, strings are immutable so you cannot modify a string like you do an array


#3

You don’t need to count individual letters, look at what the line of code there already does.

It loops over all the words in words and keeps only those that are over a certain length