Question: I have an array of objects in the following form

```
var data = [{"name":"Lenovo Thinkpad 41A4298","website":"google"},
{"name":"Lenovo Thinkpad 41A2222","website":"google"},
{"name":"Lenovo Thinkpad 41Awww33","website":"yahoo"}];

```

I want to convert this to

```
var data = [{"Brand":"Lenovo Thinkpad 41A4298","Link":"google"},
{"Brand":"Lenovo Thinkpad 41A2222","Link":"google"},
{"Brand":"Lenovo Thinkpad 41Awww33","Link":"yahoo"}];

```

How do I achieve this?

Answer: 
Using foreach loop

```js
var data = [{
    "name": "Lenovo Thinkpad 41A4298",
    "website": "google"
  },
  {
    "name": "Lenovo Thinkpad 41A2222",
    "website": "google"
  },
  {
    "name": "Lenovo Thinkpad 41Awww33",
    "website": "yahoo"
  }
];

var Result = [];

var Key = Object.keys(data[0]); // get keys in a variable

// use index insted of specific key

data.forEach(function(item) {
  Result.push({    Brand: item[Key[0]],    Link: item[Key[1]]  });
});

console.log(Result);
```
Like this:

```js
var data = [{ "name": "Lenovo Thinkpad 41A4298", "website": "google" },
{ "name": "Lenovo Thinkpad 41A2222", "website": "google" },
{ "name": "Lenovo Thinkpad 41Awww33", "website": "yahoo" }];

const newData = data.map(obj => ({ Brand: obj.name, Link: obj.website }));
console.log(newData);
```

---

To make it more dynamically, you can create some mappings:

```js
    var data = [{ "name": "Lenovo Thinkpad 41A4298", "website": "google" },
    { "name": "Lenovo Thinkpad 41A2222", "website": "google" },
    { "name": "Lenovo Thinkpad 41Awww33", "website": "yahoo" },
    { "rate": "25", "review": "Well done" }];

    const mappings = {
      name: 'Brand',
      website: 'Link',
      review: 'Review',
      rate: 'Rate'
    }

    const newData = data.map(obj => {
      const newObj = {};
      const keys = Object.keys(mappings);
      keys.forEach(key => {
         if (obj[key]) {
           const newName = mappings[key];
           newObj[newName] = obj[key];
         }
      });
      return newObj;
    });

    console.log(newData);
```

Then you can just change "mappings" based on source data or whatever you want to do with it.