# Seek and destroy - function call within indexOf()?

**URL:** <https://forum.freecodecamp.org/t/seek-and-destroy-function-call-within-indexof/84696>\
**Category:** General\
**Created:** [February 7, 2017, 7:31am UTC](https://forum.freecodecamp.org/t/seek-and-destroy-function-call-within-indexof/84696 "2017-02-07T07:31:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![afreeroad](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/afreeroad/32/140363_2.png) [@afreeroad](https://forum.freecodecamp.org/u/afreeroad)\
**Post date:** [February 7, 2017, 7:31am UTC](https://forum.freecodecamp.org/t/seek-and-destroy-function-call-within-indexof/84696/1 "2017-02-07T07:31:22Z")

</div>

I just don’t understand how “function (arg)” works. It has no value, so how does the code know what its looking for within the indexOf()?

“arr” is arguments[0], and “newArray” is the array I made for arguments[1] and [2] etc…but, what is “arg”?

return arr.filter(function (arg) {  
return newArray.indexOf(arg) === -1;  
});

---

<div class="post-metadata">

**Author:** ![batjko](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/batjko/32/4115_2.png) [@batjko](https://forum.freecodecamp.org/u/batjko)\
**Post date:** [February 7, 2017, 7:40am UTC](https://forum.freecodecamp.org/t/seek-and-destroy-function-call-within-indexof/84696/2 "2017-02-07T07:40:36Z")

</div>

> [@afreeroad](#):
>
> return arr.filter(function (arg) { return newArray.indexOf(arg) === -1; });

I don’t recall the challenge (it’s been some time), but if your question is about the .filter function and its callback, most array functions like this will take a callback function who will receive an element from the array as parameter.

So if `arr = [1,2,3,4]`, then arr.filter() will loop over this array and `function(arg){}` will become `function(1){}`, then `function(2){}`, then `function (3){}` and finally `function(4){}`.

For `filter` you can then use this argument to make a boolean expression.

e.g.:

```js
const allEvens = arr.filter(function(arg) {
  return arg % 2 === 0;
});

```

…which will return true for all even numbers and false for odd ones. `allEvens` will become an array of all the even numbers our of `arr`.

In your own example above, `newArray.indexOf(arg) === -1` will return true if `arg` (any element from your original array) was found in `newArray`. So your `filter` will filter out all those elements that exist in both the old and the new array.

Is that what you were asking?

---

<div class="post-metadata">

**Author:** ![afreeroad](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/afreeroad/32/140363_2.png) [@afreeroad](https://forum.freecodecamp.org/u/afreeroad)\
**Post date:** [February 7, 2017, 10:01am UTC](https://forum.freecodecamp.org/t/seek-and-destroy-function-call-within-indexof/84696/3 "2017-02-07T10:01:16Z")

</div>

Great response, thank you.

The main point - what I was looking for - I now understand to be that “function (arg)” is iterations of the array with which we are using filter() - in this case, “arr”.

I do understand the rest of the logic, but was stuck on what “arg” consisted of. Thank for you the other example as well.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:25pm UTC](https://forum.freecodecamp.org/t/seek-and-destroy-function-call-within-indexof/84696/4 "2021-01-16T17:25:07Z")

</div>

Closed on January 16, 2021, 5:25pm UTC


