javascript - map.delete(key) during map.forEach -
typically, cannot safely delete items list while you're looping through list. concept remain true es6 maps?
i tried simple test without exceptions:
var map = new map([['a',1],['b',2],['c',3]]); map.foreach((value,key,map)=> { map.delete(key); }); console.log(map); it seems ok.
update: read reference mozilla. doable. i'd interested in performance benchmarks comparing method of deletion other methods (on larger datasets).
why? if working same instance, can delete. have functions used delete item, can delete.
but side of optimization don't delete item map or array. javascript engines have optimizations based on shape of object. if same on refers object, optimized. instead of create new object filtered values of current object.
var map = new map([['a',1],['b',2],['c',3]]); map.foreach((value,key,map)=> { map.delete(key); }); console.log(map); there languages ( c# ), can't remove item ienumerable in for each loop, because works way under hood, gives read , update access, not delete.
Comments
Post a Comment