Node.js 주특기 심화 [3일차]
오늘은 sql 구문으로 vscode에서 테이블을 만들고 수정하고 삭제하는 것에 대해서 배웠다 많이 써보긴 했는데 아직 확실하게 머릿속에 들어온 부분은 아니라 내일 완벽해지면 정리해야겠다.
오늘 알고리즘 스터디를 하며 평소에 써보지 못했던 메서드 몇 개를 접하게 되었다.
조금 신기하기도 하고 낯설기도 해서 몇 개 정리해보려 한다.
Math.abs()
parameter에 들어온 값을 절대값으로 리턴해주는 메서드이다.
join()
join 메서드는 배열의 모든 요소를 연결해 하나의 문자열로 만들어주는 메서드이다.
join안에 특정 문자열을 넣어 배열의 요소를 연결할 때 중간 중간에 join에 넣었던 문자를 끼워넣을 수 있다.
const elements = ['Fire', 'Air', 'Water'];
console.log(elements.join());
// Expected output: "Fire,Air,Water"
console.log(elements.join(''));
// Expected output: "FireAirWater"
console.log(elements.join('-'));
// Expected output: "Fire-Air-Water"
substring()
substring 메서드는 string 객체의 시작 인덱스부터 종료 인덱스 전까지 부문자열의 부분 문자열을 반환한다.
str.substring(indexStart[, indexEnd])
const str = 'Mozilla';
console.log(str.substring(1, 3));
// Expected output: "oz"
console.log(str.substring(2));
// Expected output: "zilla"
parseInt()
상대적으로 많이 봤던 메서드이다. 하지만 정확한 사용법을 알고 싶어 정리하게 되었다.
parseInt 함수는 문자열을 파싱하여 특정 진수의 문자열을 반환한다.
parseInt(string);
parseInt(string, radix);
기본적으로 위와 같은 형태로 쓴다
string
: 파싱할 값이다. 문자열이 아닐 경우 toString 추상 연산을 사용해 문자열로 변환한다.
radix
: string의 진수를 나타내는 2 ~ 36 까지의 정수이다. 기본값은 10이 아니라는 것에 주의해야 한다. Number 자료형이 아닌 경우 Number 자료형으로 변환한다.
예시
document.writeln(parseInt("10")); // 10
document.writeln(parseInt("-10")); // -10
document.writeln(parseInt("10.9")); // 10
document.writeln(parseInt(10)); // 10
document.writeln(parseInt("10n")); // 10
document.writeln(parseInt("10nnn13")); // 10
document.writeln(parseInt(" 10")); // 10
document.writeln(parseInt("10 ")); // 10
document.writeln(parseInt("k10")); // NaN
document.writeln(parseInt("")); // NaN
// -----------------------------------------
document.writeln(parseInt("10", 2)); // 2
document.writeln(parseInt("2", 2)); // NaN
document.writeln(parseInt("0xF")); // 15
document.writeln(parseInt("0XF")); // 15
document.writeln(parseInt("0XFkk")); // 15
'TIL' 카테고리의 다른 글
2023_12_04 TIL (2) | 2023.12.05 |
---|---|
2023_12_01 TIl (1) | 2023.12.01 |
2023-11-29 TIL (0) | 2023.11.30 |
2023-11-28 TIL (1) | 2023.11.28 |
2023_11_27 TIL (0) | 2023.11.28 |