Baseline 2023
Newly available
Array
ì¸ì¤í´ì¤ì toSorted()
ë©ìëë sort()
ì ëìëë ë³µì¬ ë²ì ì ë©ìëì
ëë¤. ì´ ë©ìëë ììë¤ì ì¤ë¦ì°¨ìì¼ë¡ ì ë ¬í ìë¡ì´ ë°°ì´ì ë°íí©ëë¤.
toSorted()
toSorted(compareFn)
매ê°ë³ì
compareFn
Optional
ìì ìì를 ê²°ì íë í¨ìì
ëë¤. ìëµíë©´ ë°°ì´ ììë 문ìì´ë¡ ë³íëê³ ê° ë¬¸ìì ì ëì½ë ì½ë í¬ì¸í¸ ê°ì ë°ë¼ ì ë ¬ë©ëë¤. ìì¸í ì ë³´ë sort()
를 ì°¸ê³ íì기 ë°ëëë¤.
ììë¤ì ì¤ë¦ì°¨ìì¼ë¡ ì ë ¬í ìë¡ì´ ë°°ì´ì ëë¤.
ì¤ëªcompareFn
매ê°ë³ìì ëí´ ë ììë³´ë ¤ë©´ sort()
를 참조íì¸ì.
í¬ì ë°°ì´ìì toSorted()
ë©ìëë ë¹ ì¬ë¡¯ì undefined
ê°ì¼ë¡ ê°ì£¼íê³ ìíí©ëë¤.
toSorted()
ë©ìëë ë²ì© ë©ìë ì
ëë¤. this
ê°ì´ length
ìì±ê³¼ ì ì í¤ ìì±ì ê°ì§ê³ ìë¤ê³ ê°ì í©ëë¤.
const months = ["Mar", "Jan", "Feb", "Dec"];
const sortedMonths = months.toSorted();
console.log(sortedMonths); // ['Dec', 'Feb', 'Jan', 'Mar']
console.log(months); // ['Mar', 'Jan', 'Feb', 'Dec']
const values = [1, 10, 21, 2];
const sortedValues = values.toSorted((a, b) => a - b);
console.log(sortedValues); // [1, 2, 10, 21]
console.log(values); // [1, 10, 21, 2]
ë ë§ì ì¬ì© ìì ë sort()
를 참조íì¸ì.
ë¹ ì¬ë¡¯ì undefined
ê°ì¼ë¡ ê°ì£¼ëì´ ì ë ¬ë©ëë¤. ë¹ ì¬ë¡¯ì íì ë°°ì´ì ëì¼ë¡ ì ë ¬ëë©° compareFn
ì í¸ì¶ëì§ ììµëë¤.
console.log(["a", "c", , "b"].toSorted()); // ['a', 'b', 'c', undefined]
console.log([, undefined, "a", "b"].toSorted()); // ["a", "b", undefined, undefined]
ë°°ì´ì´ ìë ê°ì²´ìì toSorted() í¸ì¶í기
toSorted()
ë©ìëë this
ì length
ìì±ì ì½ìµëë¤. ê·¸ë° ë¤ì 0
ë¶í° length - 1
ê¹ì§ì ë²ìì ìë 모ë ì ì í¤ ìì±ì ìì§íì¬ ì ë ¬íê³ ì ë°°ì´ì ìëë¤.
const arrayLike = {
length: 3,
unrelated: "foo",
0: 5,
2: 4,
3: 3, // lengthê° 3ì´ê¸° ë문ì toSorted()ë ì´ë¥¼ 무ìí©ëë¤
};
console.log(Array.prototype.toSorted.call(arrayLike));
// [4, 5, undefined]
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
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