how to sepaarte text in object javascript


let data = 'Child 1 First Name: AlinChild 1 Gender: FemalenChild 1 Hair Color: BlondenChild 1 Hair Style: WavynChild 1 Skin Tone: TannChild 2 First Name: Morgan nChild 2 Gender: FemalenChild 2 Hair Color: BrownnChild 2 Hair Style: PonytailnChild 2 Skin Tone: LightnRelationship 1 to 2: BrothernRelationship 2 to 1: Brothern';
let target = {};

data.split('n').forEach((pair) => {
if(pair !== '') {
let splitpair = pair.split(': ');
let key = splitpair[0].charAt(0).toLowerCase() + splitpair[0].slice(1).split(' ').join('');
target[key] = splitpair[1];
}
});

console.dir(target);

www.codegrepper.com
www.stackoverflow.com