"How do I find the place for a given number in a JavaScript Array?"

First off, the right way to phrase this is:

How to find the index of an integer in a JavaScript array?

You have Array elements, which make up the array. Each element has an index. Arrays start at index 0 and count up.

To find the index of an integer, simply use the indexOf( ) method:

function getIndexToIns(arr, num) {
  var combined = 
    arr.concat(num).sort((a, b) => a - b);
    
  return combined.indexOf(num);
}

getIndexToIns([40, 60], 50);
Show Comments

var.pop( )

Web Development Tips & Tricks