I’m attempting to join all keys/values that have the same number. So for example, if the key name is alfa0: 'theValueOfAlfa'
and there is another key with the same number (in this case 0) beta0: 'theValueOfBeta'
, I would like to join them and return a object:
{
name: 'theValueOfAlfa',
value: 'theValueOfBeta'
}
This object:
const vls = {"lote0": "jg", "lote1": "h", "lote2": "fm", "loteQnt0": "jgvalue", "loteQnt1": "hvalue", "loteQnt2": "fmvalue" }
the expected output:
const result = [
{
name: 'jg',
value: 'jgvalue'
},
...
]
2
Answers
I create this snippet which can deal with the case. I don't believe this is the best approach, but it is a solution
You can simply achieve this by iterating over an object to get the keys in an array and then fetch the numbers using
RegEx
and then perform the assignment into a new object.Live Demo :