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);
```
Array.map may be your friend - returns a new array with each element being the returned result of the function you pass to the .map function.

Mozilla Developer Network link to Array.map reference [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)

In this example

* the function takes the first object in the array
* Creates a new object to return
* assigns a key of "Brand" to the new object and assigns the "name" value from the old object to it
* assigns a key of "Link" to the new object and assigns it the "website" value from the old object to it
* returns the new object that gets put into a new array that will eventually get assigned to newData
* Repeats this for each element in the array

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

let newData = data.map((originalObject)=>{
  return {
    "Brand":originalObject.name,
    "Link":originalObject.website
    }
})

console.log(newData)
```

If you want to get even fancier - you can use object destructing [here - about half way down](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) to make the code a little neater

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

let newData = data.map(( {name,website} )=>{
  return {
    "Brand":name,
    "Link":website
    }
})

console.log(newData)
```