Baseline Widely available
TypedArray
ì¸ì¤í´ì¤ì at()
ë©ìëë ì ì ê°ì ë°ì í´ë¹ ì¸ë±ì¤ì ìë í목ì ë°ííë©°, ìì ì ìì ìì ì ì를 모ë íì©í©ëë¤. ìì ì ìë ë°°ì´ì ë§ì§ë§ í목ììë¶í° ììì¼ë¡ ì
ëë¤. ì´ ë©ìëë Array.prototype.at()
ì ëì¼í ìê³ ë¦¬ì¦ì ê°ì§ëë¤.
const int8 = new Int8Array([0, 10, -10, 20, -30, 40, -50]);
let index = 1;
console.log(`An index of ${index} returns the item ${int8.at(index)}`);
// Expected output: "An index of 1 returns the item 10"
index = -2;
console.log(`An index of ${index} returns the item ${int8.at(index)}`);
// Expected output: "An index of -2 returns the item 40"
구문 매ê°ë³ì
index
ë°íí ë°°ì´ ììì 0ë¶í° ììíë ì¸ë±ì¤ë¡, ì ìë¡ ë³íë©ëë¤. ìì ì¸ë±ì¤ë íìí ë°°ì´ ëë¶í° ììì¼ë¡ ì
ëë¤. index < 0
ì¸ ê²½ì°, index + array.length
ë¡ ì ê·¼í©ëë¤.
주ì´ì§ ì¸ë±ì¤ì ì¼ì¹íë íìí ë°°ì´ì ììì
ëë¤. index < -array.length
ëë index >= array.length
ì¸ ê²½ì°, í´ë¹ ìì±ì ì ê·¼íì§ ìê³ íì undefined
를 ë°íí©ëë¤.
ë³´ë¤ ìì¸í ì ë³´ë Array.prototype.at()
를 ì°¸ê³ íì기 ë°ëëë¤. ì´ ë©ìëë ë²ì©ì ì´ì§ ìì¼ë©°, íìí ë°°ì´ ì¸ì¤í´ì¤ììë§ í¸ì¶í ì ììµëë¤.
ìë ìì ë 주ì´ì§ ë°°ì´ìì 맨 ë§ì§ë§ì ìì¹í ê°ì ë°ííë í¨ìì ëë¤.
const uint8 = new Uint8Array([1, 2, 4, 7, 11, 18]);
// 주ì´ì§ ë°°ì´ìì ë§ì§ë§ ìì를 ë°ííë í¨ì
function returnLast(arr) {
return arr.at(-1);
}
const lastItem = returnLast(uint8);
console.log(lastItem); // 18
ë¹êµ ë©ìë
ìë ìì ììë TypedArray
ì ë¤ìì ë ë²ì§¸ ìì를 ì ííë ë¤ìí ë°©ë²ì ë¹êµí©ëë¤. ìëì 모ë ë°©ë²ì´ ì í¨íì§ë§, at()
ë©ìëì ê°ê²°ì±ê³¼ ê°ë
ì±ì ê°ì¡°í©ëë¤.
// ëª ê°ì§ ê°ì´ ìë íìí ë°°ì´
const uint8 = new Uint8Array([1, 2, 4, 7, 11, 18]);
// length ìì± ì¬ì©í기
const lengthWay = uint8[uint8.length - 2];
console.log(lengthWay); // 11
// slice() ë©ìë ì¬ì©í기. ë°°ì´ì´ ë°íëë걸 ëª
ì¬íì¸ì
const sliceWay = uint8.slice(-2, -1);
console.log(sliceWay[0]); // 11
// at() ë©ìë ì¬ì©í기
const atWay = uint8.at(-2);
console.log(atWay); // 11
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4