Why let a = [{}] and a.indexOf({}) -1? [duplicate] - javascript

This question already has answers here:
How to determine equality for two JavaScript objects?
(82 answers)
How do I check if an array includes a value in JavaScript?
(60 answers)
Closed 3 years ago.
IndexOf cannot find my object. Here is the JsFiddle
let a = [{}]
console.log(a.indexOf({}))

Related

Difference between Array(1) and [...Array(1)] [duplicate]

This question already has answers here:
Allocate new array in javascript
(3 answers)
When can an empty array be iterated over?
(4 answers)
JavaScript "new Array(n)" and "Array.prototype.map" weirdness
(14 answers)
Closed 1 year ago.
What's the difference between Array(1) and [...Array(1)]? I was sure that both are equivalent until I saw that both behave differently regarding .map:
console.log(Array(1).map(() => 1));
console.log([...Array(1)].map(() => 1));
Why do they behave differently even though both return [undefined]?
console.log(Array(1));
console.log([...Array(1)]);

Are Javascript objects always unique [duplicate]

This question already has answers here:
How to determine equality for two JavaScript objects?
(82 answers)
How to explain object references in ECMAScript terms?
(1 answer)
Javascript Object Identities
(6 answers)
Closed 1 year ago.
If I do:
const o1 = {};
const o2 = {};
is it guaranteed that o1===o2 is false?

what's the role of slice method here ? why need it? [duplicate]

This question already has answers here:
Why do Array.prototype.slice.call(nodeList) for DOM elements?
(2 answers)
Explanation of [].slice.call in javascript?
(9 answers)
Closed 2 years ago.
In ES5 if have a NodeList and want to loop through it must first convert it to Array with slice and call. I can't understand correctly how this statement works. I need explanation.
let nodeList = document.querySelectorAll('div');
let nToArr = Array.prototype.slice.call(nodeList);
// Then Loop Through it ....

Can Array.prototype.includes() search for an Array? [duplicate]

This question already has answers here:
Why are two identical objects not equal to each other?
(9 answers)
How to compare arrays in JavaScript?
(55 answers)
Closed 4 years ago.
Consider the following code:
let a = [
["10.237.77.82", "10.237.79.255"],
["10.237.78.2", "230.0.0.1"],
["10.237.78.2", "10.237.79.255"]
]
console.log(a.includes(["10.237.77.82", "10.237.79.255"]))
I was expecting the includes() to find the Array ["10.237.77.82", "10.237.79.255"], why isn't it the case?
Array.prototype.includes() documentation does not seem to suggest specific elements which are "foundable" (although the examples are only with an Integer or a String)

What is the difference between `{ }` and `[ ]`? [duplicate]

This question already has answers here:
What is the difference between these arrays?
(5 answers)
Closed 9 years ago.
In JavaScript, what is the difference between
var stack = {};
and
var stack = [];
The first one is an empty object and the second is an empty array.

Categories

Resources