I have an object with values like this
const objectValues = {
weight: ["0|5"],
species: ["human|alien"],
colour: ["Blue-Green|Red|Black|Orange With Green, Red, Yellow And Blue Play Of Colour"],
shape: ["Rough"],
uniqueId: "kobe"
}
I want to turn this into an object that looks like this:
const desiredObject = {
weight: ["0","5"],
species: ["human","alien"],
colour: ["Blue-Green","Red","Black","Orange With Green, Red, Yellow And Blue Play Of Colour"],
shape: ["Rough"],
uniqueId: "kobe"
}
I thought this function i wrote would do it:
let pipeToCommaObject = {};
const mapSplitted = Object.keys(objectValues).map(key => {
if(objectValues[key].join().includes('|')){
pipeToCommaObject[key] = objectValues[key].join().split('|');
}
});
However it's not quite doing it, please advise what i'm missing and what i need to change/add to get my desired result. I think the issue might be that uniqueId is just a string by itself where as all the other properties are in an array. I need it to leave the string as is, but do the operations on the array values.