W
W
wwwx3m2019-12-17 10:57:16
API
wwwx3m, 2019-12-17 10:57:16

Is set.has(value) possible under given conditions?

I'm learning JS. Couldn't find an answer:
let xyz = new Set();
xyz.add({ name: "John" });
console.log(xyz.has({ name: "John" })); // false
Question:
Based on the condition above, is there a way to find out xyz.has for { name: "John" } in xyz ?
I'm not interested in any solution to this problem, but in finding out why it is possible / not possible to do xyz.has({ name: "John" }) in the above example.
PS:
I know the solution. Because arrays, like objects, are equal to each other only if they are literally the same piece of computer memory, then:
let xyz = new Set();
let john = { name: "John" };
xyz.add(john);
console.log(xyz.has(john)); // true
But I don't know the answer to the question.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
4
4_point, 2019-02-08
@4_point

Check out this service https://developer.bitaps.com/forwarding , bitcoins are sent immediately after confirmation to the address you specified.

W
wwwx3m, 2019-12-17
@wwwx3m

There is a solution for given conditions:
xyz.forEach ((value) => {
if (value["name"] == "John") console.log("found");
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question