I have a bothersome length of characters before all keys in this object. Since they are all the same, I would like to do a .map() or forEach() or some
.map()
forEach()
let obj = { 'remove.this.string.a': "apple", 'remove.this.string.b': "banana", 'remove.this.string.c': "carrot", 'remove.this.string.d': "diakon" }; let transformed = Object.entries(obj).reduce((t, [key, value]) => { t[key.substr(19)] = value; return t; }, {}); console.log(transformed);