Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

About Function and Parameter

New to Javascript, still confused about parameter

Here are some codes:

var people = [{ 
 name: 'Casey', 
 rate: 60
},
{
 name: 'Camille',
 rate: 80
},
{
 name: 'Gordon',
 rate: 75
},
{
 name: 'Nigel',
 rate: 120
}
];
function priceRange(person) { 
return (person.rate >= 65) && (person.rate <= 90); 
 };
var results = []; 
results = people.filter(priceRange); 

I know this is a very basic question, but I just want to know the parameter "person".How did the computer know the parameter "person" is coming from the object "people"?

Answer*

Draft saved
Draft discarded
Cancel
2
  • Thanks, I understand how does the filter() works, I just more confuse about the question of transferring parameter. I know person is the parameter in the priceRange() function, but how did "person" came from and why did person.name equals to people.name? Commented Jan 23, 2017 at 3:37
  • Keep the following callback's rule in your mind : You can choose any name for argument (person, element, ...item, however you should keep the order (person is the 1st arg, index is the 2nd arg.. so on) Commented Jan 23, 2017 at 5:27

lang-js

AltStyle によって変換されたページ (->オリジナル) /