Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Q:ES6 map.keys() after map.delete(key)

when I try these code:

const map=new Map([['a', 1],['b', 2],['c', 3],['d', 4],['e', 5]]);
console.log(map.keys());
map.delete('a')
console.log(map.keys());

the chrome console will show these:

MapIterator {"a", "b", "c", "d", "e"}
MapIterator {"c", "d", "e"}

"b" why not show up?

like image 689
俞常爽 Avatar asked Dec 24 '17 11:12

俞常爽


People also ask

What does the delete function do when used with map?

The delete() method removes the specified element from a Map object by key.

How can you remove all elements inside of a map object?

map. clear(obj); map. obj() takes an object as a parameter and removes each and every value so as to make it empty.

How do I delete a map key?

To delete a key from a map, we can use Go's built-in delete function. It should be noted that when we delete a key from a map, its value will also be deleted as the key-value pair is like a single entity when it comes to maps in Go.

How do I delete an object in maps?

delete() function in JavaScript. The delete() function of Map object accepts a string representing the key of an element of a map and deletes from the current Map object. This function returns true if the specified key exists in the map object else it returns false.


1 Answers

This is a browser compatibility issues, that happens with map.keys(), map.values(), map.entries().

The issue occurs in chrome when deleting the first key but it works when well in safari.

Also these properties don't even work in Mozilla, just returns an empty Map iterator

like image 160
Shubham Khatri Avatar answered Oct 18 '22 15:10

Shubham Khatri