5
I got the following Array
string:
["TagFuncao:CN Evento:TODOS", "TagFuncao:DOC.AGRO.INDUS Evento:TODOS"]
I need to transform this Array into an Object Array where TagFuncao
and Evento
is property of the Object, and CN
and TODOS
is the corresponding value of each property.
I did some tests on the browser console and arrived at the following result:
var newArr = r.map(i => {
var x = i.split(' ');
var p1 = x[0].replace('TagFuncao:','')
var p2 = x[1].replace('Evento:', '')
var obj = {
tagFuncao: p1,
evento: p2
}
return obj
})
Upshot:
[{tagFuncao: "CN", evento: "TODOS"}, {tagFuncao: "DOC.AGRO.INDUS", evento: "TODOS"}]
At first it solves my problem, but it doesn’t seem to be one of the best ways to do.
Question:
There are other ways to do this and achieve the same result that is not like this?
Note that this is not what you need, https://answall.com/questions/105978/converter-array--of-objects-para-um-array-de-arrays
– user187421