Array Methods - Help please!


I need help please.
Let’s find the index of a particular element in groceryList using .indexOf() .

Call .indexOf() on groceryList to find the index of the element 'pasta' and save the returned value to a const variable named pastaIndex .

Then log pastaIndex to the console. (You may remove the other console.log() statements to declutter the terminal.)


The simplistic syntax with functions in JavaScript is this:


It can be used with other functions and variables. Here’s an example:

const aVariable = object.function(argument1, argument2);

Adding arguments depend on the definition of a function.

So if we apply this with the step you’re struggling with, it should be this:

const pastaIndex = groceryList.indexOf('pasta');

Let’s also not forget to log the variable we saved it to, as it is instructed.



When they are attributes of an object, they are methods.


Well technically we call them methods. They are basically still functions.

methods vs. functions


That cannot be argued; they are synonymous. The semantics help us distinguish functions that belong to an object or class from free standing functions that can be invoked without calling them on a class or creating an instance. We could technically think of all functions as methods of the window object.

Some silliness, for levity…

 > function foo(){ = function() {
           return "bar";
       return "foo";
<- undefined
 > a = new foo()
<- foo {bar: ƒ}
<- "bar"
<- "foo"