Skip to content

Instantly share code, notes, and snippets.

View naveenrawat51's full-sized avatar
🏠
Working from home

naveenrawat51@gmail.com naveenrawat51

🏠
Working from home
View GitHub Profile
@naveenrawat51
naveenrawat51 / getLastInMap.js
Created November 11, 2021 03:59 — forked from tizmagik/getLastInMap.js
ES6 Last Item in Map()
// Since ES6 Map()'s' retain their order of insertion, it can sometimes be useful to get the last item or value inserted:
export const getLastItemInMap = map => Array.from(map)[map.size-1]
export const getLastKeyInMap = map => Array.from(map)[map.size-1][0]
export const getLastValueInMap = map => Array.from(map)[map.size-1][1]
// Obviously getLastKey and getLastValue can reuse getLastItem, but for maximum portability I opted for verbosity.