Created
June 27, 2020 09:55
-
-
Save tonkotsuboy/efca15d750dd129b2c6b8e9e6b6a66b0 to your computer and use it in GitHub Desktop.
配列の最初の要素、長さ、最終要素をワンライナーで取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 配列の最初の要素、長さ、最終要素をワンライナーで取得する | |
// 参考: https://twitter.com/argyleink/status/1139415654132436993 | |
// 対象の配列 | |
const myArray = ["😸", "🐶", "🐟", "🦆", "🐳", "🦉"]; | |
// firstに最初の要素、lに長さ, lastに最終要素 | |
const { 0: first, length: l, [l-1]: last} = myArray; | |
// 確認のため出力。結果は{first: "😸", l: 6, last: "🦉"} | |
console.log({first, l, last}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment