@acwoss/

Filtro de Array com generator

Nodejs

https://pt.stackoverflow.com/q/207642/5878

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const myArray = [
    { "name": "nome1" },
    { "name": "nome2" },
    { "name": "nome3" },
    { "name": "nome4" },
    { "name": "nome5" }
];

let qParam = "nome3";

const filterByName = name => value => value.name == name;

const user = myArray.filter( filterByName(qParam) )[0];

console.log(user);
node v10.16.0