【study】数组,对象获取最后一个值

52 阅读1分钟
  1. 数组
let arr = [2,3,4]
const Len = arr[arr.length-1]  // 4
  1. 对象
let obj = {
  2: true,
  3: true,
  4: true
}
const Len = Object.keys(obj)[Object.keys(obj).length - 1]; // 4