Arrays


#1

var bucketList = ['swim with penguins','graduate college','learn to code'];

bucketList.push('teach in Tibet','move west like a cowboy','swim the great barrier reef');

  1. Push Method

My code is coming through as [Function: push] do you know why it would be this way?

var bucketList = ['swim with penguins','graduate college','learn to code'];

bucketList.push('teach in Tibet','move west like a cowboy','swim the great barrier reef');
console.log(bucketList.push);

#2

You seem to be misunderstanding the concept of "push". When you call push on an array, you are adding values. So you made your bucketlist array, pushed (or added) the EXACT same values you already had in your array, and then attempted to print out bucketList.push, instead of just printing the bucketList.


#3

Thank you for your help sgt.schultz. I edited my script above using "push" to add different values, and then printed my bucketList. Is this correct?


#4

Yes, I hope I solved your problem. Just wanted to say as a side note that you are not required to push values to an array to make it work (obviously unless codecademy instructs you to or it is necessary in your program). And regarding printing it... printing yourArray.push makes the computer freak out because it is illogical. Push is a function used ONLY for adding values to an array. Once you call push, the values are added to the array so when you print your array those values are printed because they were added before your print statement


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.