Where do I belong algorithm

hi, guys, I hope you fine.
actually, I already solved this problem.
but as usual, I liked to see the other solutions to expand my knowledge.
and I stuck with the advance one … could you please help me to understand this one.
we should return the lowest index at which a value should be inserted into an array.
but I’m so confused how the indexOf method solved it because I know when the number does not exist in the array the indexOf return -1 …

function getIndexToIns(arr, num) {
  arr.push(num);
  arr.sort(function(a, b){return a-b});
  return arr.indexOf(num);
}

getIndexToIns([10, 20, 30, 40, 50], 35)

thank you so much for helping,
I really don’t know how I couldn’t notice the push method :flushed: