That's correct, you have to use the same array (as in map.get(arr)
), not just an equivalent array. Key comparison is like ===
(except that NaN
matches itself). So just like this shows false
:
console.log([0, 1, 2, 3] === [0, 1, 2, 3]); // false
Separate arrays aren't ===
to each other - your arr
does not refer to the same array container as the [0,1,2,3]
that you pass to map.get
. To do something like this, you'd have to iterate over the map's keys and find the one whose values all match:
const map = new Map()
const arr = [0,1,2,3];
map.set(arr, "I am some number")
// Get a reference to the same `arr` whose key you set previously:
const arrKey = [...map.keys()].find(
key => Array.isArray(key) && JSON.stringify(key) === JSON.stringify([0, 1, 2, 3])
);
console.log(map.get(arrKey));
In my console's browser, when I do : console.log(typeof(typeof)) it returns an error Uncaught SyntaxError: Unexpected token ')' Why is that? Why can't I get typeof's type ?
In my console's browser, when I do : console.log(typeof(typeof)) it returns an error Uncaught SyntaxError: Unexpected token ')' Why is that? Why can't I get typeof's type ?
ul element that has dynamically loaded li a children, sometimes the li a populate empty innerHTML. How do I remove all of the li elements that have an empty a child? Current (errors Uncaught ...
ul element that has dynamically loaded li a children, sometimes the li a populate empty innerHTML. How do I remove all of the li elements that have an empty a child? Current (errors Uncaught ...
I'm building a Node.js app (Node v10.11.0) and want to do it in a OOP-way without using Typescript. So I've built some classes like this: class Component { constructor(param1, param2, param3) { ...
I'm building a Node.js app (Node v10.11.0) and want to do it in a OOP-way without using Typescript. So I've built some classes like this: class Component { constructor(param1, param2, param3) { ...
So I am trying to build my first react.js app and am wondering, why my page does neither update after POSTING a new player to my app via axios, nor after DELETING one. As I refresh the page afterwards ...
So I am trying to build my first react.js app and am wondering, why my page does neither update after POSTING a new player to my app via axios, nor after DELETING one. As I refresh the page afterwards ...