To Modify an array stored in an object(new)

I have been sitting on this problem for 2 days now and I haven’t been able to come up with an applicable solution to it.
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/modify-an-array-stored-in-an-object

I somehow managed to get this far.

function addFriend(userObj, friend) {
  // Only change code below this line
  user.data.friends.push(friend)
  return user.data.friends.splice(friend);
  // Only change code above this line
}

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

I feel abit lost there and I am trying to figure out how to do it…

user.data.friends.push(friend)

The above line is incorrect. There is no user variable. You need to use userObj.

Also, the return statement is incorrect. You need to only return the friends array: return userObj.data.friends;

1 Like

@piedcipher thank you, thank you so much. I didn’t see it and this solution works. thank you again.

1 Like

Awesome! :tada: I’m glad I could help you :heart: