This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mainArr = ['apple', 'banana', 'mango', 'grapes', 'orange']; | |
// mainArr.slice(start, end) - start & end are indexes. JS index starts with 0. | |
const shallowArr = mainArr.slice(1, 4); | |
// includes 1 & excludes 4. | |
shallowArr | |
> ['banana', 'mango', 'grapes'] | |
const onlyStart = mainArr.slice(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mainArr = ['apple', 'banana', 'mango', 'grapes', 'orange']; | |
const negativeIndex = mainArr.slice(-4); | |
// 1: | |
negativeIndex; | |
> ........... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ObjectsArray = [ | |
{id: '1', name:'vk'}, | |
{id: '2', name:'js'} | |
]; | |
const sliced = ObjectsArray.slice(1); | |
sliced | |
> 0: {id: '2', name: 'js'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str = 'Welcome to vkglobal just code'; | |
// copies entire string. | |
str.slice(); | |
> 'Welcome to vkglobal just code' | |
// between indexes. Count spaces too. | |
str.slice(11,19); | |
> 'vkglobal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str = 'Welcome to vkglobal just code'; | |
const negativeToPositiveRange = str.slice(-11, 10); | |
// 1: | |
negativeToPositiveRange; | |
> ...................... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const num = 10.5; | |
console.log(Math.round(num)); // 11 | |
console.log(Math.ceil(num)); // 11 | |
console.log(Math.floor(num)); // 10 | |
const num1 = 10.4; | |
console.log(Math.round(num1)); // 10 | |
console.log(Math.ceil(num1)); // 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const num = 10.547; | |
console.log(Math.trunc(num)); | |
> 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const num = 10.547; | |
const num1 = -10.547; | |
console.log(Math.abs(num)); // 10.547 | |
console.log(Math.abs(num1)); // 10.547 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const num = 9; | |
console.log(Math.pow(num, 2)); // 81 | |
console.log(Math.sqrt(num)); // 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(Math.max(3,4,5,1,2)); // 5 | |
console.log(Math.min(3,4,5,1,2)); // 1 |
OlderNewer