반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

undefined

Method - indexOf/slice/replace/repeat/Math 본문

Javascript

Method - indexOf/slice/replace/repeat/Math

JavaScripter 2022. 5. 10. 20:52
반응형

// 매서드 thing.method(arg) argument = 인수

let msg = " Hello, World";

const whisper = message.toLowerCase().trim();

 

// indexOf()

msg = "Hello, World";

msg.indexOf("Hello"); // 0

msg.indexOf("o"); // 4

 

//slice(beginIndex, endIndex) 하나일때와 beginIndex는 이상 // endIndex는 미만

msg = "Hello, World";

msg.slice(7); //Wolrd

msg.slice(0, 5); // Hello

msg.slice(-5); // World

 

//replace(out,in)

msg = "Hello, World";

msg.replace("Hello", "Welcome"); //Welcome World

 

//repeat(count)

"lol".repeat(3); //"lollollol"

 

//Math()

Math.ceil(2.1); // 3

Math.floor(2.1); // 2

Math.round(2.6); // 3

 

// random은 0~1까지의 수 // Math.floor(Math.random * 갯수) + 최소값

Math.floor(Math.random() * 10) + 1; // 1~10

Math.floor(Math.random() * 5) + 1; // 1~5

Math.floor(Math.random() * 3) + 20; // 20~22

반응형

'Javascript' 카테고리의 다른 글

API 와 AJAX  (0) 2022.05.26
비동기식 함수 Promise/Async /Await  (0) 2022.05.25
for...of loop  (0) 2022.05.18
Method - splice, sort  (0) 2022.05.13
Comparison Operator  (0) 2022.05.12
Comments