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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var total = array.reduceRight(function(accumulator, currentValue, currentIndex, array){ | |
return accumulator + currentValue; | |
}, 0) | |
console.log(total); | |
// 55 (10 + 9 ... 2 + 1) |
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
var example = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var test = Array.isArray(example); | |
console.log(test); | |
// true |
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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var lastIndexOfOne = array.lastIndexOf(1); | |
var lastIndexOfFive = array.lastIndexOf(5); | |
var lastIndexOfTwenty = array.lastIndexOf(20); | |
console.log(lastIndexOfOne); // 9 | |
console.log(lastIndexOfFive); // 5 | |
console.log(lastIndexOfTwenty); // -1 |
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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var indexOfOne = array.indexOf(1); | |
var indexOfFive = array.indexOf(5); | |
var indexOfTwenty = array.indexOf(20); | |
console.log(indexOfOne); // 0 | |
console.log(indexOfFive); // 4 | |
console.log(indexOfTwenty); // -1 |
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
var array1 = [1, 2, 3, 4]; | |
var array2 = [5, 6, 7, 8]; | |
var array3 = [9, 10, 11, 12]; | |
var array = array1.concat(array2, array3); | |
console.log(array); | |
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] |
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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
console.log(array.length); | |
// 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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var arrayLength = array.unshift(-2, -1, 0); | |
console.log(array); | |
// [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
console.log(arrayLength); | |
// 13 |
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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var removedElement = array.shift(); | |
console.log(array); | |
// [2, 3, 4, 5, 6, 7, 8, 9, 10] | |
console.log(removedElement); | |
// 1 |
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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var removedElement = array.pop(); | |
console.log(array); | |
// [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
console.log(removedElement); | |
// 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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var arrayLength = array.push(11, 12, 13); | |
console.log(array); | |
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
console.log(arrayLength); | |
// 13 |