In an array of value 

```
var legends =['some','key', 'value'];

```

a graph with the respective obj values;

```
var graph = {
  orgid: ['123', '123556', '456', '345', '2345'],
  some: [1500, 1500, 1500, 1500, 1500],
  key: [900, 900, 900, 900, 900],
  value: [1072, 1373, 946, 715, 276]
 };

```

I wanted to extract the graph with only key values mentioned in an array to be inserted into another array

I have executed the code but it only works if the order of the keys which are the same in the order mentioned in the obj

**es5 way** 

```
var grphFilter = [];
var countRaw = 0; 
for (var key in graph) {
  if (key === legends[count] ) {
    grphFilter.push(graph[key]);
    count++;
  }
}

```

**es6 way** 

```
let grphFilter = [];
let count = 0; 
const result = Object.entries(graph).forEach(function([key, value]) {
  if (key === legends[count]) {
    grphFilter.push(value);
    count++
  }
})

```

but it won't work for the keys which are not in order like. 

```
var legendsNotOrder =['key', 'some', 'value'];

```

irrespective of the order of the value in the legends array, the result should be the final result, be it `legends` or `legendsNotOrder`

Final Result

```
var graphfiltered = [
  [1500, 1500, 1500, 1500, 1500],
  [900, 900, 900, 900, 900],
  [1072, 1373, 946, 715, 276]
];

```