So lets assume we know what an Array is already and jump into Filter & String Object!
// TODO: 'filter' out students whose name begins with "A"
const listOfStudents =
['Adam','Goose','Steve','Ace','Maverick','Aaron']
const aNameStudents = listOfStudents.filter(function(student) {
return student.startsWith('A')
})
In the example above 🔼 Filter returns New Array with elements that meet some Boolean condition.👆 Filter returns the current element 'student' if our Callback returns true ✅ Soo we know from my last post that JS distinguishes between 'Primitive Strings' & now we have heard of 'String Objects'..Im not going to give the MDN definition in this post 🦾 But Primitive values like 'num', cant have properties or methods(because they are not objects) under the hood JS, treats primitive values as objects when executing methods and properties... 'startsWith' 🔼 is one of those invoked string methods that is going to return with a true or false if string starts with 'A'..
Top comments (0)