Why do we need list function?


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661


Why do we need list function in this code:


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

var search = function(name) {
  for(var prop in friends) {
    if(friends[prop].firstName === name) {
      console.log(friends[prop]);
      return friends[prop];
    }
  }
};

I mean we have 'for in' loop (**for(var prop in friends)**) in search function that seems to do the same thing, so can we do without this part:
var list = function(obj) {
  for(var prop in obj) {
    console.log(prop);
  }
};
?


#2

It's a simple generic utility that can list all the primary keys of any object.


#3

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