I have a array
with id
and description
where you have 2 roles , Owner and Tenant , I was trying to separate the role from each description
and add it to a array
new one with its id
corresponding, something like:
{
id: 1,
description: "Propietario"
},
{
id: 2,
description: "Arrendatario"
}
I have the following code:
var rent = "Arrendatario";
var owner = "Propietario";
var obj = [{
id: 1,
description: "1664 - Propietario"
},
{
id: 2,
description: "1637 - Arrendatario - Finalizado"
},
{
id: 3,
description: "1735 - Arrendatario"
},
{
id: 4,
description: "LA6780 - Arrendatario"
},
{
id: 5,
description: "1638 - Arrendatario - Finalizado"
}
];
console.log(obj);
The problem is that I need to separate the word Tenant or Owner from the String something with split()
To perform the task you just have to go through the
array
and add elements to the new onearray
according to whether the value of the attributedescription
containsArrendatario
orPropietario
.As you can see the code is pretty self explanatory. The value of each attribute is checked and
array
what you want is stored in the new one.I hope it is what you were looking for.
You can solve it with a map and includes: