keepup-ECMAScript
  • About
  • Proposal
    • using
    • Temporal
  • ES2025
    • Promise.try
    • Sync Iterator helpers
    • Import Attributes
    • JSON Modules
    • New Set Methods
    • RegExp Modifiers
    • Duplicate named capture groups
  • ES2024
    • Resizable and growable ArrayBuffers
    • RegExp v flag with set notation + properties of strings
    • Atomics.waitAsync
    • Well-Formed Unicode Strings
    • array grouping
    • Promise withResolvers
  • ES2023
    • Symbols as WeakMap key
    • Hashbang Grammar
    • Array.findLast, findLastIndex
    • 配列の非破壊操作
  • ES2022
    • Private class fields
    • Regexp match indices
    • Top-level await
    • Private fields in-in
    • Array.at
    • Object.hasOwn
    • Class static block
    • Error cause
GitBook提供
このページ内
GitHubで編集
  1. ES2022

Array.at

前へPrivate fields in-in次へObject.hasOwn

最終更新 2 年前

CtrlK
  • Example
  • Link

インデックス指定で値を取り出す Array.at String.at が使えるようになった。

Example

const array = [1, 2, 3];
array.at(0); // 1
array.at(1); // 2
array.at(2); // 3

const string = "123";
string.at(0); // "1"

マイナスを指定すると末尾からの取り出しになる。

const array = [1, 2, 3];
array.at(-1); // 3

Link

JavaScript built-in: Array: at | Can I use... Support tables for HTML5, CSS3, etc
Array.prototype.at() - JavaScript | MDN
GitHub - tc39/proposal-relative-indexing-method: A TC39 proposal to add an .at() method to all the basic indexable classes (Array, String, TypedArray)GitHub
Logo
Logo
Logo