Check if a Value exists in a Map using JavaScript-Code Examples

Victor Talmacinschi

Check if a Value exists in a Map using JavaScript

JavaScript by Victor Talmacinschi June 21, 2022

// create a map
const map = new Map();

// set key-value pairs
map.set('🍔', 'Hamburger');
map.set('🍕', 'Pizza');
map.set('🌭', 'Hot Dog');

// check if a value exists in the map
if (map.has('🍔')) {
  console.log('Hamburger exists in the map!');
} else {
  console.log('Hamburger does not exist in the map.');
}

0

22.891

Check if a Value exists in a Map using JavaScript

JavaScript by Victor Talmacinschi June 21, 2022

const map = new Map();

map.set('🍎', 'Red Apple');
map.set('🍐', 'Pear');
map.set('🍊', 'Orange');

// Check if a value exists in a map
if (map.has('🍎')) {
  console.log('Red Apple exists in the map!');
} else {
  console.log('Red Apple does not exist in the map.');
}

0

22.891

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories