Javascript Array Includes

Published on June 18, 2022 | Tags: javascript TIL

Javascript arrays have a method .includes(). However, when the value is passed into the method, it is passed by reference, not by value.

This is equivalent as:

const t = { "test": "A"};
const u = { "test": "A"};
console.log(t == u); // false

Let's see a more concrete example:

> const captain = {"name": "Haddock"}
> const arr = [captain]
> arr.includes(captain)
> arr.includes({"name": "Haddock"})

Ferran Jovell