What is "prop" in the example


#1


Although I have completed the lesson but I still don't understand about the "list" and "search" segments. Why is it that in the example used there was "prop". What does it mean? Did I miss out on this somewhere?

var list = function(obj) {
for(var prop in obj) {
console.log(prop);
}
};

In general I'm also uncertain of how the code in "list" and "search" works.
Anyone can give me a brief summary?
Many thanks :slight_smile:


Replace this line with your code.


#2

prop is a variable you created, you could have named it anything you like, but prop is a good name, since it is an abbreviation of property, good choice since this loop loops over the properties (prop) of object (obj)

well, with the list function:

var list = function(obj) {
  for(var prop in obj) {
    console.log(prop);
  }
};
list(friends);

you pass friends as argument, now obj will hold the friends object. then you loop over it, prop gets assigned the property's in the friends object (bill and steve) in turn, and will log them to the console


#3

Thanks so much! I'm finally getting this.


#4

do you also understand the search function now?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.