Skip to content

Commit

Permalink
Day 28: Array Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
uttu-316 committed Nov 8, 2022
1 parent 2a3352d commit 4128451
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions javascript/Day28/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
let arr = [1, 2, 3, 4, 5];

arr.unshift(-1);
console.log(arr);
arr.shift();
console.log(arr);

const isPresent = arr.includes(-1);

console.log(isPresent);

const reversedArray = arr.reverse();

console.log(reversedArray);

const arr2 = [10, 11, 12, 13, 14, 15];

const arr3 = [-1, -2, -3, -4, -5];

const newArray = arr.concat(arr2, arr3);

console.log(newArray);

const removedValues = arr.splice(4, 2);

console.log(removedValues);
console.log(arr);

arr.splice(4, 2, -1, -2);

console.log(arr);

const stringArray = arr.toString();

console.log(stringArray);

const hypenArray = arr.join("_");
console.log(arr.join(""));

console.log(hypenArray);

const sliceArray = arr.slice(3, 7);

console.log(sliceArray, arr);

arr.fill("z");
console.log(arr);

const lastIndex = arr.lastIndexOf("a");

console.log(lastIndex);
const index = arr.indexOf("z");

console.log(index);

if (index !== -1) {
console.log("found");
} else {
console.log("not found");
}
console.log(Array.isArray(arr));

const nestedArray = [1, 2, [3, 4, [-4, 5], 8], 6, 7];

const flatArray = nestedArray.flat(2);
console.log(flatArray);

var a = [];
a.unshift(1);
a.unshift(22);
a.shift();
a.unshift(3, [4, 5]);
a.shift();
a.shift();
a.shift();

console.log(a);

0 comments on commit 4128451

Please sign in to comment.