From 0e62d546edeaee11926c343b1f56ea7e85d3053f Mon Sep 17 00:00:00 2001 From: Koushikon <54022602+Koushikon@users.noreply.github.com> Date: Sun, 12 Mar 2023 13:34:35 +0530 Subject: [PATCH] Info: moved array programs to separate section --- 02.Arrays/Array_reverse.js | 24 ++++++++++++++++++++++++ 02.Arrays/Arrays.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 02.Arrays/Array_reverse.js create mode 100644 02.Arrays/Arrays.js diff --git a/02.Arrays/Array_reverse.js b/02.Arrays/Array_reverse.js new file mode 100644 index 0000000..743ed54 --- /dev/null +++ b/02.Arrays/Array_reverse.js @@ -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) \ No newline at end of file diff --git a/02.Arrays/Arrays.js b/02.Arrays/Arrays.js new file mode 100644 index 0000000..3cddf41 --- /dev/null +++ b/02.Arrays/Arrays.js @@ -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);