I would like to insert an object into a sorted array of objects, but to know at which position to insert it :)
I have the following array of objects, the array is sorted by IP field:
let array = [{ 'ip': '192.168.0.1' }, { 'ip': '192.168.0.4'}, { 'ip': '192.168.0.10'}, { 'ip': '192.168.0.50'}, { 'ip': '192.168.0.60'}, ];
Now I would like to insert a new object to the array:
const newObject = { ip: '192.168.0.13' };
How can I add this new object to the correct position?
So that my array then looks like:
let array = [{ 'ip': '192.168.0.1' }, { 'ip': '192.168.0.4'}, { 'ip': '192.168.0.10'}, { ip: '192.168.0.13' }, { 'ip': '192.168.0.50'}, { 'ip': '192.168.0.60'}, ];
How could I find the correct index, where to insert the item ?