js get the last element of the array all in one_xgqfrms-编程思维

js get the last element of the array All In One

Array.prototype.at()

// Array.at()

const arr = [1, 2, 3, 4, 5];

let index = 1;
console.log(arr.at(index));
// 2

let lastIndex = -1;
console.log(arr.at(lastIndex));
// 5

// 等价于 👎
console.log(`\n`,arr[1]);
// 2
console.log(arr[arr.length - 1]);
// 5

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at

slice 👎

const arr = [1, 2, 3, 4, 5];

let lastIndex = -1;
console.log(arr.slice(lastIndex));
// [5]
console.log(arr.slice(lastIndex)[0]);
// 5

pop 🚀

const arr = [1, 2, 3, 4, 5];

console.log(arr.pop());
// 5

JavaScript & Array groupBy All In One

Array group

https://www.cnblogs.com/xgqfrms/p/15943811.html

refs

https://davidwalsh.name/array-prototype-at

https://flexiple.com/get-last-array-element-javascript/



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


版权声明:本文版权归作者所有,遵循 CC 4.0 BY-SA 许可协议, 转载请注明原文链接
https://www.cnblogs.com/xgqfrms/p/16403739.html

linux上的组管理-编程思维

上一次我们谈了CentOS上的用户管理,现在我们再来谈下CentOS上的用户组管理。 groupadd创建一个新的组 用法如下: groupadd [选项] groupname 常用选项: -f 强制添加一个组(这个组可能已经存在系统中) -g 指定组的id; -r

关于opc client 编写_遥望星空-编程思维

昨天又有人问我 OPC Client 编写,实际是他们不了解OPC 客户端的工作原理,要想写客户端程序,必须知道OPC对象, OPC逻辑对象模型包括3类对象:OPC server对象、OPC group对象、OPC item对象,每类对象都包括一系列接口。     OPC Server对象     主要功能为:1、创建

[mongodb]count,gourp,distinct_wolfy-编程思维

摘要 上篇文章介绍了CRUD的操作,会了这些,基本上可以完成很多工作了。但如果遇到统计类的操作,那么就需要学习下本篇的内容了。 相关文章 [MongoDB]入门操作 [MongoDB]增删改查 count,gourp,distinct,mapReduce count 作用类似sql中的count函数,用来计数。 如上

EFCore分组查询(GroupBy)后获取第一个元素-编程思维

EFCore截至目前已经更新到了5.x, 然鹅对于一些略复杂的查询的支持还是不尽如人意啊, 有时候还不得不配合dapper来使用. 引入 假如现在有这样一个登录日志表, 需要查询各用户的最近的一次登录记录, 如何用EFCore来查呢? 登录日志表结构和模拟数据如下 生成数据库脚本USE [EFCoreGroupDem