Skip to content

Commit 2117e20

Browse files
committed
adding array methods
1 parent 6e274c5 commit 2117e20

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Array Methods/flatMap.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// lets define an array
2+
let numbersArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
3+
4+
// each element of the array is cubed and then flattened
5+
const outputArray = numbersArray.flatMap((x) => [x ** 3]);
6+
7+
console.log('Output:', outputArray);
8+
9+
// Output: [1, 8, 27, 64, 125, 216, 343, 512, 729]

Array Methods/pop.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Lets create a cities array with four elements,
2+
let cities = ["Mumbai", "Delhi", "Hyderabad", "Chennai"];
3+
4+
// removes the last element from the cities array
5+
let removedCity = cities.pop();
6+
7+
console.log(`Output: ${cities}`)
8+
// Output: Mumbai,Delhi,Hyderabad
9+
10+
console.log(`Output: ${removedCity}`)
11+
// Output: Chennai

0 commit comments

Comments
 (0)