Question: I have an object like this,

```
{
    "Distrubutor":"DISTRIBUTOR1",
    "INCLUDE":"INDIA,United States",
    "EXCLUDE":"KARNATAKA-INDIA,CHENNAI-TAMILNADU-INDIA",
    "PARENT-ID":""
}

```

i want to Generate the Multiple objecs By using the INCLUDE Property in the Main object, can anybody help me on this

```
{
    "parent_id":"",
    "id":"DISTRIBUTOR1",
    "permission":"Granted",
    "country_code":"INDIA"
}

2.  
{
    "parent_id":"",
    "id":"DISTRIBUTOR1",
    "permission":"Granted",
    "country_code":"United States"
}

```

Answer: 
You could split the included countries and map new objects.

```js
var data = {"Distrubutor":"DISTRIBUTOR1","INCLUDE":"INDIA,United States","EXCLUDE":"KARNATAKA-INDIA,CHENNAI-TAMILNADU-INDIA","PARENT-ID":""},
    include = data.INCLUDE.split(',').map(function (a) {
        return {
            parent_id: "",
            id: data.Distrubutor,
            permission: "Granted",
            country_code: a                
        };
    });

console.log(include);
```

```css
.as-console-wrapper { max-height: 100% !important; top: 0; }
```
You can try something like this:

```js
var obj = {"Distrubutor":"DISTRIBUTOR1","INCLUDE":"INDIA,United States","EXCLUDE":"KARNATAKA-INDIA,CHENNAI-TAMILNADU-INDIA","PARENT-ID":""}

// Keys that does not need to be in returned object
var ignoreKeys = ["EXCLUDE", "INCLUDE"];

var tmp = Object.assign({}, obj)

// Delete all keys that are not required
ignoreKeys.forEach(function(key){ delete tmp[key] })

var result = obj.INCLUDE.split(',').map(function(country){
  return Object.assign({}, tmp, {"country_code": country, "permission": "GRANTED"})
})

console.log(result)
```

**Note:** I have used [Object.assign](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to copy but it is not supported by all browsers. Please refer [browser compatibility](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility) before using. You can also refer following post for alternatives: [What is the most efficient way to deep clone an object in JavaScript?](https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript)