How to get a last element of ES6 Map without iterations?

后端 未结 2 361
执念已碎
执念已碎 2020-12-11 15:42

How to get a last element of ES6 Map/Set without iterations(forEach or for of) pass through a full length of the container?

2条回答
  •  清歌不尽
    2020-12-11 16:00

    const getLastItemInMap = (map) => [...map][map.size-1];
    const getLastKeyInMap = (map) => [...map][map.size-1][0];
    const getLastValueInMap = (map) => [...map][map.size-1][1];
    

提交回复
热议问题