let input = fs.readFileSync(filePath).toString().split('\n'); 
   

console.log(typeof input// typeof input => object

input = input[0];  // -> object => string

console.log(typeof input) //typeof input => string

문법

 typeof variable

 

variable에는 데이터 또는 변수가 들어갑니다. 괄호를 사용해도 됩니다.

typeof(variable)

 

반환되는 값은 다음과 같습니다.

  • undefined : 변수가 정의되지 않거나 값이 없을 때
  • number : 데이터 타입이 수일 때
  • string : 데이터 타입이 문자열일 때
  • boolean : 데이터 타입이 불리언일 때
  • object : 데이터 타입이 함수, 배열 등 객체일 때
  • function : 변수의 값이 함수일 때
  • symbol : 데이터 타입이 심볼일 때

- < 알파벳-숫자 유니코드 포인트 표 >

알파벳-숫자 유니코드 관계를 일일이 외우실 필요는 없습니다. 물론 외우면 좋겠지만요. 팁을 드리자면, 대문자와 소문자의 첫 시작 알파벳인 'a'와 'A'의 유니코드만 외우시면 됩니다. 예를 들어, 영어 알파벳이 총 26개이기 때문에, 'a'에 대한 유니코드 포인트가 97이라는 것만 알면 'z'의 유니코드 포인트는 122라는 것을 알 수 있습니다.

10진수 문자열 10진수 문자열
65 A 97 a
66 B 98 b
67 C 99 c
68 D 100 d
69 E 101 e
70 F 102 f
71 G 103 g
72 H 104 h
73 I 105 i
74 J 106 j
75 K 107 k
76 L 108 l
77 M 109 m
78 N 110 n
79 O 111 o
80 P 112 p
81 Q 113 q
82 R 114 r
83 S 115 s
84 T 116 t
85 U 117 u
86 V 118 v
87 W 119 w
88 X 120 x
89 Y 121 y
90 Z 122 z

String.prototype.toLowerCase()

- toLowerCase() 메서드는 문자열을 소문자로 변환해 반환합니다.
 

구문

str.toLowerCase()

반환값

호출 문자열을 소문자로 변환한 새로운 문자열

 

예제

toLowerCase()

console.log('ALPHABET'.toLowerCase()); // 'alphabet'

 

String.prototype.repeat()

- repeat() 메서드는 문자열을 주어진 횟수만큼 반복해 붙인 새로운 문자열을 반환합니다.

구문

str.repeat(count);

- count

문자열을 반복할 횟수. 0과 양의 무한대 사이의 정수([0, +∞)).

-

반환값

- 현재 문자열을 주어진 횟수만큼 반복해 붙인 새로운 문자열.

예제

'abc'.repeat(-1);   // RangeError
'abc'.repeat(0);    // ''
'abc'.repeat(1);    // 'abc'
'abc'.repeat(2);    // 'abcabc'
'abc'.repeat(3.5);  // 'abcabcabc' (count will be converted to integer)
'abc'.repeat(1/0);  // RangeError

({ toString: () => 'abc', repeat: String.prototype.repeat }).repeat(2);
// 'abcabc' (repeat() is a generic method)

 

Array.prototype.slice()

- slice()** **메서드는 어떤 배열의 begin부터 end까지(end 미포함)에 대한 얕은 복사본을 새로운 배열 객체로 반환합니다. 원본 배열은 바뀌지 않습니다.

 

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]

console.log(animals.slice(1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]

console.log(animals.slice(-2));
// expected output: Array ["duck", "elephant"]

console.log(animals.slice(2, -1));
// expected output: Array ["camel", "duck"]

console.log(animals.slice());
// expected output: Array ["ant", "bison", "camel", "duck", "elephant"]

 

output>

> Array ["camel", "duck", "elephant"]

> Array ["camel", "duck"]

> Array ["bison", "camel", "duck", "elephant"]

> Array ["duck", "elephant"]

> Array ["camel", "duck"]

> Array ["ant", "bison", "camel", "duck", "elephant"]

 

구문

    arr.slice([begin[, end]])

 

Array.prototype.includes()

- includes() 메서드는 배열이 특정 요소를 포함하고 있는지 판별합니다.

ex)

const array1 = [1, 2, 3];

console.log(array1.includes(2));
// expected output: true

const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// expected output: true

console.log(pets.includes('at'));
// expected output: false

---------------------------------------

output>

> true

> true

> false

1. charAt()

- charAt 은 문자열에서 인자로 주어진 값에 해당하는 문자를 리턴합니다.

ex)

var stringName = 'coding everybody';
alert(stringName.charAt(0)); // c
alert(stringName.charAt(stringName.length-1)); // y
alert(stringName.charAt(1000) == ''); // true



 

2. charCodeAt()

- charCodeAt 메서드는 index에 해당하는 문자의 unicode 값을 리턴합니다.

- string.charCodeAt(index)

 

ex)


var stringName = '자바스크립트';
console.log(stringName.charCodeAt(0)); // 51088
// http://www.unicode.org/charts/PDF/UAC00.pdf 에서 '자'을 찾아보면 'C790'인데 이것은 16진수다.
// 이를 10진수로 변환하면 51088 된다.

 

3. fromCharCode()

- fromCharCode 는 아스키코드번호를 받아 문자열을 구성해주는 함수입니다.

+ Recent posts