如何在没有迭代的情况下获得 ES6 Map 的最后一个元素? [英] How to get a last element of ES6 Map without iterations?

查看:22
本文介绍了如何在没有迭代的情况下获得 ES6 Map 的最后一个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有迭代(forEach 或 for of)的情况下通过容器的全长获取 ES6 Map/Set 的最后一个元素?

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

推荐答案

映射是可迭代和有序的,但它们不是数组,因此它们没有任何索引访问.迭代到最终元素是您能做的最好的事情.最简单的情况是

Maps are iterable and ordered, but they are not arrays so they don't have any indexed access. Iterating to the final element is the best you can do. The simplest case being

 Array.from(map.values()).pop();

这篇关于如何在没有迭代的情况下获得 ES6 Map 的最后一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆