This file contains hidden or 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 days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; | |
| var copy = days.slice(); | |
| var weekend = days.slice(5); | |
| var alsoWeekend = days.slice(-2); | |
| var weekdays = days.slice(0, 5); | |
| var alsoWeekdays = days.slice(0, -2); | |
| console.log(copy); | |
| // ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] |
This file contains hidden or 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 weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]; | |
| var eg1 = weekdays.join(); | |
| var eg2 = weekdays.join(""); | |
| var eg3 = weekdays.join(" + "); | |
| console.log(eg1); | |
| // "Monday,Tuesday,Wednesday,Thursday,Friday" | |
| console.log(eg2); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |