본문 바로가기

Python_WEB/JavaScript

[freecodecamp]JavaScript 대괄호를 사용하여 문자열의 마지막 문자 찾기

반응형

문자열의 마지막 문자를 얻으려면 문자열 길이에서 하나를 뺄 수 있습니다.

예를 들어 var firstName = "Charles"인 경우 firstName [firstName.length-1]을 사용하여 문자열의 마지막 문자 값을 가져올 수 있습니다.

 

예>

var firstName = "Charles";
var lastLetter = firstName[firstName.length - 1]; // lastLetter is "s"

 

Q>

1. lastName 변수에서 마지막 문자를 찾으려면 대괄호 표기법을 사용하십시오.

2. lastLetterOfLastName은 "e"여야합니다.

3. 마지막 글자를 얻으려면 .length를 사용해야합니다.

 

A>

// Setup
var lastName = "Lovelace";

// Only change code below this line
var lastLetterOfLastName = lastName[lastName.length - 5]; // Change this line

 

https://www.freecodecamp.org/

 

freeCodeCamp.org

Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.

www.freecodecamp.org

 

반응형