Modify an Array Stored in an Object - bracket notation won't work

Tell us what’s happening:


I’m using bracket notation to solve this problem…If I change it to dot notation it works

I don’t understand why bracket notation doesn’t work. I thought I could use either?

Your code so far

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

function addFriend(userObj, friend) {
  // change code below this line  
return userObj[data][friends];
  // change code above this line

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.

Link to the challenge:

In this way the code is searching for the values hold in variables data and friends, as they are not defined it is equal to userObj[undefined][undefined]

if instead those are the exact names you need to put them in quotes

1 Like