Answer the question
In order to leave comments, you need to log in
How to implement read with delete?
Good afternoon.
I have a data structure like:
Ключ1: значение1
Ключ2: значение2
...
Answer the question
In order to leave comments, you need to log in
Not an expert in modern JS, but seems up to the task:
var hashMap = {'key1': 'value1', 'key2': 'value2'};
function get(key) {
if (hashMap[key] == null) {
return null;
}
var value = hashMap[key];
delete hashMap[key];
return value;
}
get('key1'); // "value1"
get('key1'); // null
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question