-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Info: moved array programs to separate section
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* ? Syntax: Array_name.reverse() | ||
* * Array One Method reverses the original array. | ||
* ? Syntax: [...Array_name].reverse() | ||
* * Array Another Method keeps the original array as it is and creates a new array of reversed elements. | ||
*/ | ||
|
||
const names_1 = ["Alice", "Bob", "Charlie", "David"] | ||
const reversed_1 = names_1.reverse() | ||
|
||
// Output: David, Charlie, Bob, Alice | ||
console.log(names_1) | ||
// Output: David, Charlie, Bob, Alice | ||
console.log(reversed_1) | ||
|
||
|
||
|
||
const names_2 = ["Alice", "Bob", "Charlie", "David"] | ||
const reversed_2 = [...names_2].reverse() | ||
|
||
// Output: Alice, Bob, Charlie, David | ||
console.log(names_2) | ||
// Output: David, Charlie, Bob, Alice | ||
console.log(reversed_2) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Array Elements: | ||
* -5 Index: 10 | ||
* -4 Index: 6 | ||
* -3 Index: 7 | ||
* -2 Index: 8 | ||
* -1 Index: 9 | ||
*/ | ||
var Nums = [10, 6, 7, 8, 9]; | ||
console.log(Nums.at(-5)); | ||
|
||
/** | ||
* * Array Destructurig: | ||
*/ | ||
const states = ["Abia", "Adamawa", "Anambra", "Bauchi", "Bayelsa", "Benue", "Borno", "Cross River", "Delta", "Ebonyi", "Enugu", "Edo"]; | ||
|
||
// Getting values from start and with few skip | ||
const [first, second, , fourth] = states; | ||
console.log(first, second, fourth) | ||
|
||
// Getting only specified position values | ||
const { 2: third, 5: fifth, 9: tenth } = states; | ||
console.log(third, fifth, tenth); | ||
|
||
|
||
const my = { name: 'Random People', company: 'Andela' }; | ||
const { name } = my; | ||
console.log(name); | ||
const { name: Human } = my; | ||
console.log(Human); |