[js, ts] number타입 전화번호 배열 string타입으로 바꾸기(' - '삽입)
JavaScript에서 number타입 전화번호 string타입 배열 전화번호로 바꾸기 - map과 정규식을 사용하여 변환한다. 코드 const holidays = [ 20230101, 20230121, 20230122, 20230123, 20230124, 20230301, 20230505, 20230527, 20230529, 20230606, 20230815, 20230928, 20230929, 20230930, 20231003, 20231009, 20231225, ]; const transformHolidays = (number: Number[]) => { let newArray: string[] = []; number.map((e, i) => { newArray[i] = e .toString() ...
2023. 5. 2.
[js] 배열 합치기(concat(), spread 연산자, push())
Javascript에서 2개 이상의 배열을 하나의 배열로 만드는 3가지 방법 1. concat()을 이용한 배열 합치기 2. spread 연산자를 이용한 배열 합치기 3. push()를 이용한 배열 합치기 1. concat()을 이용한 배열 합치기 const arr1 = ['a', 'b', 'c']; const arr2 = ['d', 'e', 'f']; const arr3 = arr1.concat(arr2); console.log(arr3); 출력값 ['a', 'b', 'c', 'd', 'e', 'f'] 2. Spread 연산자를 이용한 배열 합치기 const arr1 = ['a', 'b', 'c']; const arr2 = ['d', 'e', 'f']; const arr4 = [...arr1, ...a..
2023. 4. 25.
[js, ts] 정규식을 이용하여 공백, 전화번호에서의 -, 특수문자 제거 함수
[js, ts] 정규식을 이용하여 공백, 전화번호에서의 -, 특수문자 제거 함수등 export const trimAll = (str: string) => { const trimStr = str.replace(/\s/g, ""); return trimStr; }; 공백을 제거하는 함수이다. export const trimHpNumber = (str: string) => { const trimStr = str.replaceAll("-", ""); return trimStr; }; 전화번호 ( - ) 제거하는 함수이다. const EX_MARK: /[\{\}\[\]\/?.,;:|\)*~`!^\-_+@\#$%&\\\=\(\'\"]/gi, // 특수문자가 들어가 있는가? export const CHAR_DEL =..
2023. 4. 7.