- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Javascript search for an object key in a set
The Set class in JavaScript provides a has method to search elements in a given set object. In case you want to search for a object in a set, you need to provide the reference to that object. Identical objects with different memory addresses are not considered equal. This method can be used as follows −
Example
let mySet = new Set(); let myObj = {name: "John"} mySet.add(1); mySet.add(3); mySet.add("a"); mySet.add(myObj); console.log(mySet) console.log(mySet.has(myObj)) // Considered as a new object console.log(mySet.has({name: "John"}))
Output
Set { 1, 2, 3, 'a' } true false
Advertisements
To Continue Learning Please Login
Login with Google