-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathslice.js
37 lines (32 loc) · 1.36 KB
/
slice.js
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
32
33
34
35
36
37
"use strict";
// TOPIC /////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Array Method: .slice()
//
// SYNTAX ////////////////////////////////////////////////////////////////////////////////////////////////////
//
// string.slice(beginSlice, endSlice);
//
// SUMMARY ///////////////////////////////////////////////////////////////////////////////////////////////////
//
// • .slice() extracts a selection of a string and returns it as a new string without modifying
// the original string.
// •
//
// EXAMPLES //////////////////////////////////////////////////////////////////////////////////////////////////
//
// EXAMPLE 1: Create a function that creates a new string from an exisitng one.
//
// RESOURCES /////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EXAMPLE 1: Create a function that creates a new string from an exisitng one.
const myString = "This is a string";
function sliceIt(string, beginSlice, endSlice) {
const sliceString = string.slice(beginSlice, endSlice);
console.log(sliceString);
}
sliceIt(myString, 1); // his is a string
sliceIt(myString, 1, 4); // his