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
If you've already got lodash, _.mapKeys
is what you're looking for. Here's an example of what you asked for directly (to just slice to 19 characters), but you could easily do a split or replace or whatever else you'd like:
var _ = require('lodash')
let data = {
'remove.this.string.a': "apple",
'remove.this.string.b': "banana",
'remove.this.string.c': "carrot",
'remove.this.string.d': "diakon"
}
_.mapKeys(data, (val, key) => key.slice(19))
Here's a runkit: https://runkit.com/daedalus28/slice-keys