Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript Create a RegEx 
Javascript :: jquery select input value empty and hasclass 
Javascript :: javascript loop last index 
Javascript :: how to use text onclick to display images in javascript 
Javascript :: how to add image url in tailwindconfig .js 
Javascript :: vuejs pass all events to child 
Javascript :: if browser reactjs 
Javascript :: how to find the radius of a loacation in node js 
Javascript :: vbscript popup message box with timer 
Javascript :: auto increase hight of textarea with alpine js 
Javascript :: hover javascript 
Javascript :: react extends component Increment data 
Javascript :: angular dropdown selected value 
Javascript :: last index of array js 
Javascript :: how to use datepicker apply to send a get request 
Javascript :: set radgrid datasource clientside 
Javascript :: formating decimal hours as hours and minute javascript 
Javascript :: check if an element is displayed jquery 
Javascript :: What Is A ReadableStream 
Javascript :: 2d array in javascript 
Javascript :: how to get all scripts on a page javascript 
Javascript :: js if the reverse of a number is better than the original num 
Javascript :: window.history 
Javascript :: linear search algorithm in javascript 
Javascript :: how to check alphabet case in javascript 
Javascript :: javascript add item by index 
Javascript :: order by type 
Javascript :: json returning object object 
Javascript :: generate string from regex javascript 
Javascript :: havascript The toExponential() Method 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =