[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] string ๋ฉ”์„œ๋“œ ์ •๋ฆฌ โœจ

2024. 11. 12. 11:45ยท์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ •์„ ๐ŸŸก

 

 

 

 `concat()`

  • ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋œ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ํ˜ธ์ถœ ๋ฌธ์ž์—ด์— ๋ถ™์ธ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
const str1 = 'hello'
const str2 = 'world'

str1.concat(' ', str2)

 `includes()`

  • ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด์ด ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ํŒ๋ณ„
  • ๊ฒฐ๊ณผ๋ฅผ true false๋กœ ๋ฐ˜ํ™˜
const sentence = 'The quick brown fox jumps over the lazy dog.';

const word = 'fox';

sentence.includes(word) ? 'is' : 'is not'

 

`indexOf()`

  • `string` ๊ฐ์ฒด์—์„œ ์ฃผ์–ด์ง„ ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๋Š” ์ฒซ๋ฒˆ์งธ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜
  • ๊ฐ’์ด ์—†์œผ๋ฉด -1๋กœ ๋ฐ˜ํ™˜
const paragraph = "I think Ruth's dog is cuter than your dog!";

const searchTerm = 'dog';
const indexOfFirst = paragraph.indexOf(searchTerm);

console.log(indexOfFirst) //15

`lastIndexOf()`

  • ์ฃผ์–ด์ง„ ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„์„ `fromIndex`๋กœ๋ถ€ํ„ฐ ์—ญ์ˆœ์œผ๋กœ ํƒ์ƒ‰
  • ์ตœ์ดˆ๋กœ ๋งˆ์ฃผ์น˜๋Š” ์ธ๋ฑ์Šค ๋ฐ˜ํ™˜
  • ์—†์œผ๋ฉด -1๋กœ ๋ฐ˜ํ™˜
const paragraph = "I think Ruth's dog is cuter than your dog!";

const searchTerm = 'dog';

console.log(paragraph.lastIndexOf(searchTerm)) //38

 


 

`padEnd()`

  • ์ด ๋ฌธ์ž์—ด์„ ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด๋กœ ์ฑ„์›Œ์„œ ๊ฒฐ๊ณผ ๋ฌธ์ž์—ด์ด ์ง€์ •๋œ ๊ธธ์ด์— ๋„๋‹ฌํ•˜๋„๋ก ํ•จ
const str1 = 'Breaded Mushrooms';

console.log(str1.padEnd(25, '.')
//Breaded Mushrooms........
"abc".padEnd(10); // "abc       "
"abc".padEnd(10, "foo"); // "abcfoofoof"
"abc".padEnd(6, "123456"); // "abc123"
"abc".padEnd(1); // "abc"

`padStart()`

  • ๊ฒฐ๊ณผ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„ ๊ธธ์ด์— ๋„๋‹ฌํ•  ๋•Œ๊นŒ์ง€ ์ด ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์— ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์„ ์ฑ„์›€
const str1 = '5'

console.log(atr1.padStart(2, '0') //'05'

const fullNumber = '2034399002125581'
const last4Digits = fullNumber.slice(-4)
const maskedNumber = last4Digits.padStart(fullNumber.length, '*')

console.log(maskedNumber) // "************5581"
"abc".padStart(10); // "       abc"
"abc".padStart(10, "foo"); // "foofoofabc"
"abc".padStart(6, "123465"); // "123abc"
"abc".padStart(8, "0"); // "00000abc"
"abc".padStart(1); // "abc"

 

`repeat()`

  • ๋ฌธ์ž์—ด์„ ์ฃผ์–ด์ง„ ํšŸ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•ด ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜
str.repeat(count)
"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

 

`replace()`

  • pattern์˜ ๋‹จ์ผ, ํ˜น์€ ๋ชจ๋“  ์ผ์น˜ ํ•ญ๋ชฉ์ด replacement๋กœ ๋Œ€์น˜๋œ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
  • ๋‹จ, ์˜ค์ง ์ฒซ๋ฒˆ์งธ ํ•ญ๋ชฉ๋งŒ ๋ณ€๊ฒฝ
const paragraph = "I think Ruth's dog is cuter than your dog!";

console.log(paragraph.replace("Ruth's", 'my'));
// Expected output: "I think my dog is cuter than your dog!"

"xxx".replace("", "_"); // "_xxx"

 

`replaceAll()`

  • pattern์˜ ๋ชจ๋“  ์ผ์น˜ ํ•ญ๋ชฉ์œผ๋กœ replacement๋กœ ๋Œ€์ฒด๋œ ์ƒˆ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
const paragraph = "I think Ruth's dog is cuter than your dog!";

console.log(paragraph.replaceAll('dog', 'monkey'));
// Expected output: "I think Ruth's monkey is cuter than your monkey!"

 

`search()`

  • ์ •๊ทœ์‹๊ณผ ์ด ๋ฌธ์ž์—ด ๊ฐ„์— ์ผ์น˜ํ•˜๋Š” ํ•ญ๋ชฉ์ด ์žˆ๋Š”์ง€ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๋ฌธ์ž์—ด์—์„œ ์ฒซ ๋ฒˆ์งธ๋กœ ์ผ์น˜ํ•˜๋Š” ํ•ญ๋ชฉ์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜
const paragraph = "I think Ruth's dog is cuter than your dog!";

// Anything not a word character, whitespace or apostrophe
const regex = /[^\\w\\s']/g;

console.log(paragraph.search(regex));
// Expected output: 41

console.log(paragraph[paragraph.search(regex)]);
// Expected output: "!"

 

`slice()`

  • ๋ฌธ์ž์—ด์˜ ์ผ๋ถ€๋ฅผ ์ถ”์ถœํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
  • ์ธ๋ฑ์Šค๋Š” 0์—์„œ๋ถ€ํ„ฐ ์‹œ์ž‘
  • ์˜ˆ๋ฅผ ๋“ค์–ด, `str.slice(4, 8)`์ด๋ฉด, ๋‹ค์„ฏ ๋ฒˆ์งธ ๋ฌธ์ž๋ถ€ํ„ฐ ์—ฌ๋Ÿ๋ฒˆ์งธ ๋ฌธ์ž๊นŒ์ง€ ์ถ”์ถœ(4, 5, 6, 7)
    • ์ฆ‰, ์‹œ์ž‘ํ•˜๋Š” ์ธ๋ฑ์Šค๋Š” ํฌํ•จํ•˜๋˜ ๋งˆ์ง€๋ง‰ ์ธ๋ฑ์Šค๋Š” ํฌํ•จํ•˜์ง€ ์•Š๋Š” ๊ตฌ์กฐ
const str = 'The quick brown fox jumps over the lazy dog.';

console.log(str.slice(31));
// Expected output: "the lazy dog."

console.log(str.slice(4, 19));
// Expected output: "quick brown fox"

console.log(str.slice(-4));
// Expected output: "dog."

console.log(str.slice(-9, -5));
// Expected output: "lazy"

 

`split()`

  • ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฌธ์ž์—ด๋กœ ๋‚˜๋ˆ”
const str = 'The quick brown fox jumps over the lazy dog.';

const words = str.split(' ')
console.log(word[3]); //fox

 

`startsWith()`

  • string ๋ฉ”์„œ๋“œ๋กœ ์–ด๋–ค ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€ ๊ฒฐ๊ณผ๋ฅผ true false๋กœ ๋ฐ˜ํ™˜
const str1 = 'Saturday night plans';

console.log(str1.startsWith('Sat'));
//  true

console.log(str1.startsWith('Sat', 3));
//  false

 

`subString()`

  • string ๊ฐ์ฒด์˜ ์‹œ์ž‘ ์ธ๋ฑ์Šค๋กœ๋ถ€ํ„ฐ ์ข…๋ฃŒ ์ธ๋ฑ์Šค ์ „๊นŒ์ง€์˜ ๋ฌธ์ž์—ด์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜
  • ์˜ˆ๋ฅผ ๋“ค์–ด, `subString(1, 3)`์ด๋ฉด, 1, 2๋งŒ ์ถ”์ถœ
const str = 'Mozila'
console.log(str.substring(1, 3))
//oz

 

`String.prototype[@@iterator]()`

  • [@@iterator]() ๋ฉ”์„œ๋“œ๋Š” ์ˆœํšŒ ํ”„๋กœํ† ์ฝœ์„ ๊ตฌํ˜„ํ•˜์—ฌ ์ „๊ฐœ ๊ตฌ๋ฌธ ๋ฐ `for … of `๋ฃจํ”„์™€ ๊ฐ™์ด ๋ฐ˜๋ณต์ž๋ฅผ ๊ธฐ๋Œ€ํ•˜๋Š” ๋Œ€๋ถ€๋ถ„์˜ ๊ตฌ๋ฌธ์—์„œ ๋ฌธ์ž์—ด์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•จ
const str = "The quick red fox jumped over the lazy dog's back.";

const iterator = str[Symbol.iterator]()
let theChar = iterator.next()

while (!theChar.done && theChar.value !== ' ') {
  console.log(theChar.value)
  theChar = iterator.next()
}

// Expected output: "T"
  //                  "h"
  //                  "e"

 

`toLocalLowerCase()`

  • ์–ด๋–ค ์ง€์—ญ ํŠน์ • ๋Œ€/์†Œ๋ฌธ์ž ๋งคํ•‘์— ๋”ฐ๋ฅธ ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜๋œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜
const dotted = 'ฤฐstanbul';

console.log(`EN-US: ${dotted.toLocaleLowerCase('en-US')}`);
// Expected output: "iฬ‡stanbul"

console.log(`TR: ${dotted.toLocaleLowerCase('tr')}`);
// Expected output: "istanbul"

 

`toLocalLowerCase()`

  • ์–ด๋–ค ์ง€์—ญ ํŠน์ • ๋Œ€/์†Œ๋ฌธ์ž ๋งคํ•‘์— ๋”ฐ๋ฅธ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜๋œ ๋ฌธ์ž์—ด ๊ฐ’์„ ๋ฐ˜ํ™˜
const city = 'istanbul';

console.log(city.toLocaleUpperCase('en-US'));
// Expected output: "ISTANBUL"

console.log(city.toLocaleUpperCase('TR'));
// Expected output: "ฤฐSTANBUL"

 

`toLowerCase()`

  • ๋ฌธ์ž์—ด์„ ์†Œ๋ฌธ์ž๋กœ ๋ฐ˜ํ™˜
const sentence = 'The quick brown fox jumps over the lazy dog.';

console.log(sentence.toLowerCase());
// Expected output: "the quick brown fox jumps over the lazy dog."

 

`toUpperCase()`

  • ๋ฌธ์ž์—ด์„ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ˜ํ™˜
const sentence = 'The quick brown fox jumps over the lazy dog.';

console.log(sentence.toUpperCase());
// Expected output: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."

 

`toString()`

  • ๊ฐ์ฒด์˜ ๋ฌธ์ž์—ด ํ‘œํ˜„์„ ๋ฐ˜ํ™˜
const stringObj = new String('foo') //{ 'foo' }

console.log(stringObj.toString()) // 'foo'

 

`valueOf()`

  • ๋ฌธ์ž์—ด์˜ ๊ฐ’์„ ๋ฐ˜ํ™˜
const stringObj = new String('foo');

console.log(stringObj);
// Expected output: String { "foo" }

console.log(stringObj.valueOf());
// Expected output: "foo"

 

`trim()`

  • ๋ฌธ์ž์—ด ์–‘ ๋์˜ ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๋ฉด์„œ ์›๋ณธ ๋ฌธ์ž์—ด์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜
const greeting = '   Hello world!   ';

console.log(greeting);
// Expected output: "   Hello world!   ";

console.log(greeting.trim());
// Expected output: "Hello world!";

 

`trimEnd()`

  • ๋ฌธ์ž์—ด ๋งˆ์ง€๋ง‰์˜ ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๊ณ  ์›๋ณธ ๋ฌธ์ž์—ด ์ˆ˜์ • ์—†์ด ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜
const greeting = '   Hello world!   ';

console.log(greeting);
// Expected output: "   Hello world!   ";

console.log(greeting.trimEnd());
// Expected output: "   Hello world!";

 

`trimgStart()`

  • ๋ฌธ์ž์—ด ์‹œ์ž‘์˜ ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๊ณ  ๊ธฐ์กด ๋ฌธ์ž์—ด์˜ ์ˆ˜์ •์—†์ด ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜
const greeting = '   Hello world!   ';

console.log(greeting);
// Expected output: "   Hello world!   ";

console.log(greeting.trimStart());
// Expected output: "Hello world!   ";

'์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ •์„ ๐ŸŸก' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ์ œ๋„ˆ๋ ˆ์ดํ„ฐ ํ•จ์ˆ˜, ์ดํ„ฐ๋Ÿฌ๋ธ” ๊ฐ์ฒด โœจ  (3) 2024.11.11
[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] CommonJS vs ES Modules  (1) 2024.09.10
[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ์ฝœ๋ฐฑ, Promise, async/await  (0) 2024.08.12
[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] callback ์ •๋ฆฌ โœจ  (0) 2024.01.28
[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ํ”„๋กœํ† ํƒ€์ž… ์ •๋ฆฌ โœจ  (0) 2024.01.26
'์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ •์„ ๐ŸŸก' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ์ œ๋„ˆ๋ ˆ์ดํ„ฐ ํ•จ์ˆ˜, ์ดํ„ฐ๋Ÿฌ๋ธ” ๊ฐ์ฒด โœจ
  • [์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] CommonJS vs ES Modules
  • [์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] ์ฝœ๋ฐฑ, Promise, async/await
  • [์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] callback ์ •๋ฆฌ โœจ
์ฝ”๋”ฉํ•˜๋Š” ํฌ๋ฃจ
์ฝ”๋”ฉํ•˜๋Š” ํฌ๋ฃจ
ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž์˜ ๊ณต๋ถ€ ํ…ƒ๋ฐญ ๊ฐ€๊พธ๊ธฐ ๐ŸŒฑ
  • ์ฝ”๋”ฉํ•˜๋Š” ํฌ๋ฃจ
    ๊ฐœ๋ฐœ ํ…ƒ๋ฐญ ๐ŸŒฑ
    ์ฝ”๋”ฉํ•˜๋Š” ํฌ๋ฃจ
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (59)
      • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ •์„ ๐ŸŸก (20)
      • React์˜ ๊ณ ์ˆ˜ ๐ŸŸข (9)
      • ํด๋ผ์šฐ๋“œ์— ๊ด€ํ•˜์—ฌ โ˜๏ธ (5)
      • Next.js ์ตํžˆ๊ธฐ ๐Ÿ”ต (1)
      • ํ”„๋ก ํŠธ์—”๋“œ ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป (21)
      • ์ •๋ฆฌ ๋ชจ์Œ โœจ (3)
  • ๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

    • ํ™ˆ
    • ํƒœ๊ทธ
    • ๋ฐฉ๋ช…๋ก
  • ๋งํฌ

  • ๊ณต์ง€์‚ฌํ•ญ

  • ์ธ๊ธฐ ๊ธ€

  • ํƒœ๊ทธ

    ์ธ์ฆ/์ธ๊ฐ€
    ํ”„๋ก ํŠธ์—”๋“œํ”„๋ ˆ์ž„์›Œํฌ
    AWS ํด๋ผ์šฐ๋“œ
    aws ์„œ๋น„์Šค
    ํ”„๋กœ๋ฏธ์Šค์ง€์˜ฅ
    ์ฝœ๋ฐฑ
    HTTP์™„๋ฒฝ๊ฐ€์ด๋“œ
    ๋ทฐ์ œ์ด์—์Šค
    function๊ณผ arrow function
    as const
    ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ
    const enum
    amazon lattice
    ํƒ€์ž… ๋‹จ์–ธ
    javascrirpt
    ๋„คํŠธ์›Œํฌ ์ œ์–ด ๋ชฉ๋ก
    AWS
    ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ด€๋ฆฌ
    OSI๊ณ„์ธต
    ๋ ˆ์ŠคํŠธ ์—ฐ์‚ฐ์ž
    amazon nova
    js
    cloud practitioner
    ์ฝœ๋ฐฑ์ง€์˜ฅ
    Amazon Bedrock
    ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฐ”์ธ๋”ฉ
    q developer
    ๋‹ค๋žŒ์ฅ์ฑ…
    ์ œ์–ด๊ถŒ ์œ„์ž„
    ๋ธŒ๋ผ์šฐ์ € ๊ฐ์ฒด
  • ์ตœ๊ทผ ๋Œ“๊ธ€

  • ์ตœ๊ทผ ๊ธ€

  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.1
์ฝ”๋”ฉํ•˜๋Š” ํฌ๋ฃจ
[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ] string ๋ฉ”์„œ๋“œ ์ •๋ฆฌ โœจ
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”