728x90
✨ String의 인덱스를 지정하는 또 다른 방법
💻Example Code
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
const str = 'Hi there! my friend!'; | |
const index = 3; | |
console.log(str.charAt(index)); |

🧨 물론 직접 지정하는 것도 가능하지만, 조금 더 graceful 표현이 필요할 때, 또는 목적에 맞게 사용 가능하다.
프로젝트는 보통 다수의 인원이 참여하게 되는데, 내 코드를 다른 사람도 이해할 수 있어야 한다.
따라서, 내가 작성한 코드의 목적을 정확히 표현하고 싶을 때 사용할 수 있다.
👉 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
String.prototype.charAt()
The String object's charAt() method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string.
developer.mozilla.org
'JavaScript > Built-in Method etc.' 카테고리의 다른 글
Array.prototype.find() (0) | 2020.06.09 |
---|---|
Array.prototype.splice() (2) | 2020.05.15 |
Set (Object) (0) | 2020.02.20 |
String.prototype.localeCompare() (0) | 2020.02.20 |
Math.round() (0) | 2020.02.16 |