Basic Data Structures: Modify an Array Stored in an Object

What is the reason why this is returning me 4 instead of returning the array [“Sam”, “Kira”, “Tomo”, “Pete”]

let user = {
  name: 'Kenneth',
  age: 28,
  data: {
    username: 'kennethCodesAllDay',
    joinDate: 'March 26, 2016',
    organization: 'freeCodeCamp',
    friends: [
      'Sam',
      'Kira',
      'Tomo'
    ],
    location: {
      city: 'San Francisco',
      state: 'CA',
      country: 'USA'
    }
  }
};

function addFriend(userObj, friend) {
  // Only change code below this line
           
          for(let a in userObj){
             
                  let array= user.data.friends;
                  let newFriend=array.push(friend); 
                  return newFriend;
          }
            
  // Only change code above this line
}

console.log(addFriend(user, 'Pete'));


Return value

The new length property of the object upon which the method was called.

I am grateful for you time.

let user = {
  name: 'Kenneth',
  age: 28,
  data: {
    username: 'kennethCodesAllDay',
    joinDate: 'March 26, 2016',
    organization: 'freeCodeCamp',
    friends: [
      'Sam',
      'Kira',
      'Tomo'
    ],
    location: {
      city: 'San Francisco',
      state: 'CA',
      country: 'USA'
    }
  }
};

function addFriend(userObj, friend) {
  // Only change code below this line
           
          for(let a in userObj){
             
                  let array= user.data.friends;
                  let newFriend=array.push(friend); 
                  return array;
          }
            
  // Only change code above this line
}

console.log(addFriend(user, 'Pete'));

What is the purpose of for … in iteration?

The variable a from for…in statement is never used.

The return statement ends the function execution on the first iteration and returns the content of the array array.