Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to sepaarte text in object javascript

let data = 'Child 1 First Name: Ali
Child 1 Gender: Female
Child 1 Hair Color: Blonde
Child 1 Hair Style: Wavy
Child 1 Skin Tone: Tan
Child 2 First Name: Morgan 
Child 2 Gender: Female
Child 2 Hair Color: Brown
Child 2 Hair Style: Ponytail
Child 2 Skin Tone: Light
Relationship 1 to 2: Brother
Relationship 2 to 1: Brother
';
let target = {};

data.split('
').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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sepaarte #text #object #javascript
ADD COMMENT
Topic
Name
1+1 =