-
Notifications
You must be signed in to change notification settings - Fork 0
/
20_modifyObjectArray.js
39 lines (35 loc) · 1.09 KB
/
20_modifyObjectArray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Modify an Array Stored in an Object
/* Take a look at the object we've provided in the code editor.
The user object contains three keys. The data key
constains five keys, one of which contains an array of
friends. From this, you can see how flexible objects are as
data structures. We've started writing a function
addFriend. Finish writing it so that it takes a user object
and adds the name of the friend argurment to the array
stored in user.data.friends and returns that array. */
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
userObj.data.friends.push(friend);
return userObj.data.friends
// Only change code above this line
}
console.log(addFriend(user, 'Pete'));