How on earth does the computer know what “user” is when it’s looking for user.age?! Furthermore, if the objects in an array are not named and I don’t want to use arr[i] to iterate through them but would rather use map() or filter() to extract certain properties only, how does this mechanism work and how does the computer know where to look?
filter() is an array method, so it iterates over users array where each “user” equals to
{ name: 'John', age: 34 } and { name: 'Amy', age: 20 } and { name: 'camperCat', age: 10 } one by one.
It enters every object in array (every user) and checks if any user.age is less than 30.
Then it creates new array with objects = users that satisfy this condition.
So in this case, “user” is just an argument put into the function? That does help a lot. I’m still trying to figure out how the computer recognizes what “user” corresponds to when the function is called.
but how does the computer know that each object is called user? That’s my question. Because on other assignments with objects, I get very confused on how to locate specific properties on specific objects within an array without referencing the array index location of the object. And giving objects a random name just returns “undefined.” Could you use any random word here instead of user and it will still work?
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.