๐Ÿ—‚์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€ ๋•Œ ํ•„์ˆ˜ ์ง€์‹_๋ฌธ์ž, ์ˆ˜ํ•™ ๊ด€๋ จ

์œ ๋ฆผยท2022๋…„ 7์›” 22์ผ
0

JAVASCRIPT

๋ชฉ๋ก ๋ณด๊ธฐ
4/18
post-thumbnail

๋ฌธ์ž์—ด์˜ ๊ธธ์ด๊ฐ€ ์•Œ๊ณ  ์‹ถ๋‹ค

๋ฌธ์ž์—ด.length();

const str = "Hello, world";
console.log(str.length);
// 12

๋ฌธ์ž์—ด ์œ„์น˜ ์ฐพ๊ธฐ, indexOf!

const str = "Hello, world";
console.log(str.indexOf("world"));
// 7

๋ฌธ์ž์—ด ์ž๋ฅด๊ธฐ, slice

: ๋ฌธ์ž์—ด.slice(์‹œ์ž‘์œ„์น˜, ์ข…๋ฃŒ์œ„์น˜);

const str = "Hello, world";
console.log(str.slice(0, 5));
//Hello

๋ฌธ์ž์—ด ๋ฐ”๊พธ๊ธฐ, replace

: ๋ฌธ์ž์—ด.replace(โ€œ์ฐพ์„ ๋ฌธ์žโ€ , โ€œ๋ฐ”๊ฟ€ ๋ฌธ์žโ€);

const str = "Hello, world";
 console.log(str.replace("world", "๋ฝ€๋กœ๋กœ"));
 // Hello, ๋ฝ€๋กœ๋กœ

๋ฌธ์ž์—ด ๋ฐ˜๋ณตํ•˜๊ธฐ, repeat!

๋ฌธ์ž์—ด.repeat(๋ฐ˜๋ณต ํšŸ์ˆ˜);

let str = "์šฐ์˜";
 let longStr = str.repeat(10) + "์šฐ";
 console.log(longStr);
 //์šฐ์˜์šฐ์˜์šฐ์˜์šฐ์˜์šฐ์˜์šฐ

์•ž ๋’ค ๊ณต๋ฐฑ ๋ฌธ์ž ์ œ๊ฑฐํ•˜๊ธฐ, trim

const str = "          Hello, world       ";
 console.log(str.trim());
 // Hello, world

์ˆซ์ž๋“ค์˜ ์ข…๋ฅ˜ 2๊ฐ€์ง€, int/float

  • ์ •์ˆ˜ํ˜• ๋ณ€ํ™˜ : ์ •์ˆ˜ํ˜• ๋ณ€ํ™˜ : parseInt()

  • ๋ถ€๋™์†Œ์ˆ˜ ๋ณ€ํ™˜ : parseFloat()
    (๋ถ€๋™์†Œ์ˆ˜๋Š” 0.5์ฒ˜๋Ÿผ ์†Œ์ˆ˜์ž๋ฆฌ๊ฐ€ ์žˆ๋Š” ์ˆซ์ž๋ฅผ ์˜๋ฏธํ•œ๋‹ค)

const pi = 3.14159265358979;
console.log(pi);

let int = parseInt(pi);   
let float = parseFloat(pi);   

console.log(int);    // ์ •์ˆ˜ 3์ด ์ถœ๋ ฅ๋จ 
console.log(float);   // 3.14159265358979 ๋ถ€๋™์†Œ์ˆ˜ ํ˜•ํƒœ๋กœ ์ถœ๋ ฅ๋จ
console.log(typeof int, typeof float); // number๋ผ๊ณ  ์ถœ๋ ฅ๋จ

์ˆ˜ํ•™๊ด€๋ จ ํ•จ์ˆ˜๋“ค : Math

console.log("abs: ", Math.abs(-999));       // ์ ˆ๋Œ€๊ฐ’ 999

console.log("min: ", Math.min(10, 33));     // ์ž‘์€ ๊ฐ’ 10
 
console.log("max: ", Math.max(10, 33));     // ํฐ ๊ฐ’ 33


 
console.log("ceil: ", Math.ceil(3.14));     // ์˜ฌ๋ฆผ 4
 
console.log("floor: ", Math.floor(3.14));   // ๋ฒ„๋ฆผ 3
 
console.log("round: ", Math.round(3.6));    // ๋ฐ˜์˜ฌ๋ฆผ 4
 
console.log("round: ", Math.round(3.4));    // ๋ฐ˜์˜ฌ๋ฆผ 3



console.log("random: ", Math.random());     // ๋žœ๋ค ์•„๋ฌด์ˆซ์ž
profile
ษช สœแดแด˜แด‡ แด›แด sแดสŸแด แด‡ ส€แด‡แด€สŸ แด˜ส€แดส™สŸแด‡แดs๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ปโค๏ธ

0๊ฐœ์˜ ๋Œ“๊ธ€