const arr = [
{ val: 1, from: 0, to: 25 },
{ val: 2, from: 9, to: 13 },
{ val: 3, from: 14, to: 20 }];
const output = [[0, 9], [9, 13], [14, 20], [20, 25]];
const arr = [
{ val: 1, from: 0, to: 25 },
{ val: 2, from: 9, to: 13 },
{ val: 3, from: 14, to: 20 }]
const output = arr
.map(el=>[el.from, el.to])
.flat()
.sort((a,b)=>a-b)
.map((el, index, array)=>array[index+1] && [el, array[index+1]])
.filter(el=>el)