JS - Replace text in multiple locations

by Eugene Vilder

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.19/fabric.min.js"></script>

JavaScript

let string='How much money has Rebecca Black made off of Friday?';

const replaceRange = (s, start, end, substitute) => s.substring(0, start) + substitute + s.substring(end);

let array=
[{
    offset: 19,
    length: 13
}, {
    offset: 25,
    length: 6
}];
array.sort(function(a,b){
  return b.offset-a.offset;
}).forEach(function(item){
    string=replaceRange(string,item.offset,item.offset+item.length,"TREE-HOUSE");
});

console.log('How much money has Rebecca Black made off of Friday?', string);