Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e24fce

Browse files
All Array Methods ✅
1 parent f0df99c commit 7e24fce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+657
-15
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎7. Array-Methods/15. from().js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Array From ()
2+
// Array.from() Method returns a new array from any array likr iterable object
3+
4+
let names = "Suhail";
5+
6+
console.log(Array.from(names)); // [ 'S', 'u', 'h', 'a', 'i', 'l' ]
7+
8+
let num = "12345";
9+
console.log(Array.from(num, (ele) => ele * ele));
10+
console.log(num);

‎7. Array-Methods/16. includes().js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Array Includes
2+
3+
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
4+
console.log(arr1.includes(10));
5+
6+
// Array Includes value in true or false
7+
// The includes() method returns:
8+
9+
// true if searchValue is found anywhere within the array
10+
// false if searchValue is not found anywhere within the array
11+
12+
// Array Includes check the given element is
13+
// present in the array or not
14+
//
15+
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
16+
17+
console.log(arr.includes(11)); // false
18+
console.log(arr.includes(4)); // true
19+
// 11 is not in the array so it gave false
20+
// 4 is in the array so it gave true
21+
22+
// The includes() method is case sensitive. For example:
23+
24+
const words = ["Java", "Python", "C"];
25+
console.log(words.includes("c")); // false
26+
// There is no lowerCase c in the array
27+
console.log(words.includes("C")); // true
28+
// There is UpperCase C in the array
29+
30+
31+
// 2nd Parameter is for to check from a specific index of array
32+
const test = [0, 1, 2, 3, 4, 5, 6, 7, 8];
33+
console.log(test.includes(4, 5)); // Checking 4 from 5th index // false
34+
console.log(test.includes(4, 1)); // Checking 4 from 1st index // true
35+

‎7. Array-Methods/17. indexof().js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Indexof Array Method
2+
3+
// Array Indexof gives the index of the specifc element from
4+
// the array
5+
6+
// IF THERE IS NO INDEX OF THAT ELEMENT IF GIVE RETURN -1
7+
8+
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
9+
10+
console.log(arr.indexOf(1)); // 0
11+
console.log(arr.indexOf(2)); // 1
12+
console.log(arr.indexOf(10)); // 9
13+
14+
const words = ["Java", "C", "C++", "Python"];
15+
// Indexs are 0 1 2 3
16+
17+
console.log(words.indexOf("JavaScript")); // -1
18+
console.log(words.indexOf("C++")); //2;
19+
console.log(words.indexOf("Java")); // 0
20+
console.log(words.at(0));

‎7. Array-Methods/18. isArray().js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Array is.Array() //
2+
// Checks the array is a array or not
3+
4+
// Returns true if the array is true
5+
// Returns false if the array is false
6+
7+
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
8+
9+
console.log(arr);
10+
11+
console.log(Array.isArray(arr));
12+
13+
//
14+
15+
const arr2 = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
16+
console.log(arr2);
17+
18+
console.log(Array.isArray(arr2));
19+
20+
console.log(typeof arr2); // Its an Object but shows as Array
21+
22+
23+
// passing an empty array []
24+
console.log(Array.isArray([])); // true
25+
26+
// we have created an array with element 7 and
27+
// passed that value to isArray()
28+
console.log(Array.isArray(new Array(7))); // true
29+
30+
// passing a boolean value
31+
console.log(Array.isArray(true)); // false
32+
33+
// passing undefined
34+
console.log(Array.isArray(undefined)); // false
35+
36+
// not passing any argument in isArray()
37+
console.log(Array.isArray()); // false

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /