-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.js
More file actions
17 lines (15 loc) · 764 Bytes
/
filter.js
File metadata and controls
17 lines (15 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* -------------------------------------------------------------------------- */
/* filter */
/* ---- retorna un nuevo arreglo con los elementos q cumplan la condición --- */
/* -------------------------------------------------------------------------- */
const arrayObjects = [
{ name: "Jhon", age: 21 },
{ name: "Camila", age: 22 },
{ name: "Kevin", age: 15 },
];
const ofAge = arrayObjects.filter((element) => element.age > 18);
console.log(ofAge);
/* [ { name: "Jhon", age: 21 }, { name: "Camila", age: 22 }]; */
const withoutJhon = arrayObjects.filter((element) => element.name !== "Jhon");
console.log(withoutJhon);
/* [{ name: "Camila", age: 22 }, { name: "Kevin", age: 15 }]; */