Introduction to Algorithms Handbook - mistake?

Hi,
I stumbled upon this article Introduction to Algorithms Handbook – with JavaScript Examples and there is 3rd example with commentary that is O(n) notation and I don’t understand how.

function twoNumberSum(array, targetSum) {
    let result = []

    for (let i = 0; i < array.length; i++) {
        let desiredNumber = targetSum - array[i]
        if (array.indexOf(desiredNumber) !== -1 && array.indexOf(desiredNumber) !== i) {
            result.push(array[i])
            result.push(array[array.indexOf(desiredNumber)])
            break
        }
    }

    return result
}

In this last example, we’re only iterating the array once, without doing anything else before. This is the best solution, since we’re performing the smallest number of operations. The complexity in this case is linear – O(n).

You have one loop though array but inside the loop we have twiced used array.indexOf which is also O(n) so overall its time complexity is O(n) * O(n) = O(n²). Is there something i’m missing?
To achieve O(n) we have to use other algorithm like below (with Set method) or i’m not understanding something?

function twoNumberSum(array, targetSum) {
  const seen = new Set()

    for (let i = 0; i < array.length; i++) {
    const desiredNumber = targetSum - array[i]
    if (seen.has(desiredNumber)) return [desiredNumber , array[i]]
    seen.add(array[i])
  }

  return []
}