How do u assign new friends/post values

How do u assign new friends/post values to the object inside the function?

It would be like invoking the method inside the object, ensure we pass a parameter as this method (addFriend) has a parameter. In the above code just add the below

newUser.addFriend('John');
console.log(newUser.friends); //This would print the entire friends array
console.log(newUser.friends[2]); //To choose to print third element in the friends array

This code would be different if we user Setter and Getter.

1 Like