I am quite bad at data manipulation and after a lot of time I was finally able to get it working how I wanted. The thing is I don't like all the delete operations, I think the code can be a lot cleaner and the runtime seems somewhat slow on a lot of data. Code readability is very important here but it needs to be small, contained and fast. ES6+ i welcome and of course so are tips and general information.

Input Data:
-----------

```
{
  agency: "",
  agent: "",
  agent_email: "",
  agent_phone: "",
  date_of_birth: "2007-05-30",
  delivery_address: "address - 1",
  delivery_city: "city - 1",
  delivery_country: "PE",
  delivery_state: "state - 1",
  delivery_zipcode: "zip_code - 1",
  facebook: "",
  instagram: "",
  name: "Dustin Peter",
  primary_email: "wagnerpeter@bailey-schroeder.example.com",
  primary_phone_number: "+31622064234",
  residential_address: "address - 0",
  residential_city: "city - 0",
  residential_country: "LC",
  residential_state: "state - 0",
  residential_zipcode: "zip_code - 0",
  secondary_email: "garzajustin@vasquez.example.com",
  secondary_phone_number: "+39349330249",
  shoe_size: "38"
  snapchat: "",
  twitter: "",
  url: "",
  youtube: "",
}

```

End Result:
-----------

**Data Set 1:**

```
{
  name: "Dustin Peter",
  primary_email: "wagnerpeter@bailey-schroeder.example.com",
  primary_phone_number: "+31622064234",
}

```

**Data Set 2:**

```
{
  date_of_birth: "2007-05-30",
  delivery_address: {
    address: "address - 1",
    city: "city - 1",
    country: "PE",
    state: "state - 1",
    zip_code: "zip_code - 1",
  }
  residential_address: {
    address: "address - 0",
    city: "city - 0",
    country: "LC",
    state: "state - 0",
    zip_code: "zip_code - 0",
  }
  secondary_email: "garzajustin@vasquez.example.com",
  secondary_phone_number: "+39349330249",
  shoe_size: "38",
}

```

My Working Code:
----------------

```
const dataSet1 = {
  name: data.name,
  primary_email: data.primary_email,
  primary_phone_number: data.primary_phone_number,
};

const dataSet2 = {};
Object.keys(data).forEach((prop) => {
    if (data[prop]) { dataSet2[prop] = data[prop]; }
});

dataSet2.residential_address = {
    address: dataSet2.residential_address,
    city: dataSet2.residential_city,
    country: dataSet2.residential_country,
    state: dataSet2.residential_state,
    zip_code: dataSet2.residential_zipcode,
};

dataSet2.delivery_address = {
    address: dataSet2.delivery_address,
    city: dataSet2.delivery_city,
    country: dataSet2.delivery_country,
    state: dataSet2.delivery_state,
    zip_code: dataSet2.delivery_zipcode,
};

delete dataSet2.name;
delete dataSet2.primary_email;
delete dataSet2.primary_phone_number;
delete dataSet2.residential_city;
delete dataSet2.residential_country;
delete dataSet2.residential_state;
delete dataSet2.residential_zip_code;
delete dataSet2.delivery_city;
delete dataSet2.delivery_country;
delete dataSet2.delivery_state;
delete dataSet2.delivery_zip_code;

```