如何获得ES6 Map的最后一个元素而不需要迭代? [英] How to get a last element of ES6 Map without iterations?

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

问题描述

如何获取ES6 Map / Set的最后一个元素,无迭代(forEach或for for)通过容器的全长?

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天全站免登陆