Course contentsShow
← JavaScript
Lesson 882 of 2,72320. Array Iteration and TransformationFree lesson

Callback Parameters: element, index, array

Master all three parameters available in callbacks for every, some, find, and findIndex methods.

Callback Parameters: element, index, array

You'll learn the three standard parameters available in callback functions for methods like every(), some(), find(), and findIndex().

The Three Parameters

When you pass a callback function to array methods like every(), some(), find(), or findIndex(), JavaScript automatically provides three parameters to your callback on each iteration:

  1. element — the current array element being processed
  2. index — the position of that element (starting from 0)
  3. array — the entire original array being iterated over

You can name these parameters whatever you like, but their position determines what they receive.

const numbers = [10, 20, 30];

numbers.find((element, index, array) => {
  console.log(`Element: ${element}, Index: ${index}, Array: ${array}`);
  return element > 15;
});
// Element: 10, Index: 0, Array: 10,20,30
// Element: 20, Index: 1, Array: 10,20,30

You Don't Need All Three

Most of the time, you only need the first parameter (the element itself). JavaScript won't complain if you ignore the others:

const hasLarge = numbers.some(num => num > 25); // Only using element

But the index and array are available when you need context:

const fruits = ['apple', 'banana', 'cherry'];

// Finding element that matches its position somehow
const found = fruits.find((fruit, index) => {
  return fruit.length === index + 5;
}); // 'apple' (length 5, index 0)

Same Pattern Everywhere

This three-parameter pattern is consistent across every(), some(), find(), findIndex(), map(), filter(), forEach(), and more—making it predictable once you learn it.

Key Takeaway: Array iteration callbacks receive three parameters by position: the current element, its index, and the full array—use whichever you need for your logic.