---
# System prepended metadata

title: forEach and filter function use

---

# forEach and filter function use

```javascript=
var wizards = [
  { name: "Edwin Odesseiron", age: 37, alignment: "lawful evil" }, 
  { name: "Harry Potter", age: 21, alignment: "neutral good"}, 
  { name: "Hermony Granger", age: 21, alignment: "lawful good"},
  { name: "Ronny the Bear", age: 21, alignment: "neutral good"},
  { name: "Gandalf", age: 100, alignment: "neutral good"}
]


// forEach
var newList = [];
wizards.forEach(function(value) {
    if (value.alignment === "neutral good") {
        newList.push(value);
    }
})


// filter
var newList = wizards.filter(function(value){
    return value.alignment === "neutral good"
})


// backend process
function filter(list, callback) {
    var newlist = [];
    for (var i = 0; i < list.length; i++) {
        if (callback(value)) {
            newlist.push(value);
        }
    }

}


if (isAlive === true) || if (isAlive)
if (isAlive !== true) || if (!isAlive)

if (isAlive === false) || if (!isAlive)
if (isAlive !== false) || if (isAlive)


var isAlive = true;

if (isAlive === true){
  console.log("we are alive") 
}
// we are alive

if (isAlive){ß
  console.log("we are alive") 
}
// we are alive

if (isAlive === false){
  console.log("we are alive") 
}
// no output
if (!isAlive){
  console.log("we are alive") 
}
// no output
```