Question: I have been struggling to get this pass from last couple of days. But could not figure out how to solve this. I'm working on a react project. Below is my problem

```js
var array = [
    {name: 'a', value: false}, 
    {name: 'b', value: false}, 
    {name: 'c', value: false}, 
    {name: 'd', value: true}, 
    {name: 'e', value: false}
]
```

I tried Javascript `filter` and `forEach` methods but couldn't figure out the perfect solution for get an array with the `names` of the objects whose `value` is `true`. Expected output for previous sample of data should be:

```
var output = ['d']

```

Answer: 
You could use only [reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) to achieve this. You add to the acc array only when the value is true.

```js
const  array = [{name: 'a', value: false}, {name: 'b', value: false}, {name: 'c', value: false}, {name: 'd', value: true}, {name: 'e', value: false}];

const res = array.reduce((acc, { name, value }) => value ? acc.concat(name) : acc, []);

console.log(res);
```
Using simple `for` loop

```js
var array = [{name: 'a', value: false}, {name: 'b', value: false}, {name: 'c', value: false}, {name: 'd', value: true}, {name: 'e', value: false}]

let op = []

for(let i=0; i<array.length; i++) {
  if(array[i].value){
    op.push(array[i].name)
  }
}

console.log(op)
```