const arr = [
{id: 1, info: 'some'},
{id: 5, info: 'some'},
{id: 3, info: 'some'},
{id: 9, info: 'some'},
{id: 6, info: 'some'},
];
const findId = (_arr, isNeedToSort) => {
const arr = isNeedToSort ? _arr.slice().sort((a ,b )=> a.id - b.id) : _arr;
for(let i = 0; i < arr.length; i++){
if(i + 1 !== arr[i].id) return i + 1;
}
}
console.log(findId(arr, true))