You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or 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
-**Definition:** Returns a shallow copy of a portion of an array into a newarray object selected from begin to end (end not included) where begin and end represent the index of items in that array.
-**Syntax:**`array.slice(begin[, end])`
-**Example:**
```javascript
let arr = [1, 2, 3, 4, 5];
let newArr = arr.slice(1, 3);
console.log(newArr); // Output: [2, 3]
```
## 7.splice()
-**Definition:** Changes the contents of an array by removing or replacing existing elements and/or adding newelementsin place.
let concat = arr.reduceRight((acc, curr) => acc + curr);
console.log(concat); // Output: 'dcba'
```
## 19. join()
- **Definition:** Creates and returns a new string by concatenating all of the elements in an array, separated by commas or a specified separator string.
- **Syntax:** `array.join(separator)`
- **Example:**
```javascript
let arr = ['Hello', 'World'];
let str = arr.join(' ');
console.log(str); // Output: 'Hello World'
```
## 20. reverse()
- **Definition:** Reverses the elements of an array in place. The first array element becomes the last, and the last array element becomes the first.
- **Syntax:** `array.reverse()`
- **Example:**
```javascript
let arr = [1, 2, 3];
arr.reverse();
console.log(arr); // Output: [3, 2, 1]
```
## 21. sort()
- **Definition:** Sorts the elements of an array in place and returns the sorted array.
- **Syntax:** `array.sort([compareFunction])`
- **Example:**
```javascript
let arr = [5, 2, 1, 4, 3];
arr.sort((a, b) => a - b);
console.log(arr); // Output: [1, 2, 3, 4, 5]
```
## 22. toString()
- **Definition:** Returns a string representing the specified array and its elements.
- **Syntax:** `array.toString()`
- **Example:**
```javascript
let arr = [1, 2, 3];
let str = arr.toString();
console.log(str); // Output: '1,2,3'
```
## 23. flat()
- **Definition:** Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
-**Definition:** Returns the element at the specified index in the array.
-**Syntax:**`array.at(index)`
-**Example:**
```javascript
let arr = [10, 20, 30, 40, 50];
console.log(arr.at(2)); // Output: 30
```
## 34.lastIndexOf()
-**Definition:** Returns the last index at which a given element can be found in the array, or -1if it is not present. Searches the array from a specified index if provided.
This file contains hidden or 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
- Definition: Returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included) where begin and end represent the index of items in that array.
- Syntax: array.slice(begin[, end])
- Example:
let arr = [1, 2, 3, 4, 5];
let newArr = arr.slice(1, 3);
console.log(newArr); // Output: [2, 3]
7. splice()
- Definition: Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
- Definition: Returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included) where begin and end represent the index of items in that array.
- Syntax: array.slice([start], [end])
- Example:
let arr = [1, 2, 3, 4, 5];
let slicedArr = arr.slice(1, 4);
console.log(slicedArr); // Output: [2, 3, 4]
26. isArray()
- Definition: Determines whether the passed value is an Array.
- Syntax: Array.isArray(value)
- Example:
let arr = [1, 2, 3];
console.log(Array.isArray(arr)); // Output: true
27. fill()
- Definition: Fills all the elements of an array from a start index to an end index with a static value.
- Syntax: array.fill(value[, start[, end]])
- Example:
let arr = [1, 2, 3, 4, 5];
arr.fill(0, 2, 4);
console.log(arr); // Output: [1, 2, 0, 0, 5]
28. keys()
- Definition: Returns a new Array Iterator object that contains the keys for each index in the array.
This file contains hidden or 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
- Definition: Returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included) where begin and end represent the index of items in that array.
- Syntax: array.slice(begin[, end])
- Example:
let arr = [1, 2, 3, 4, 5];
let newArr = arr.slice(1, 3);
console.log(newArr); // Output: [2, 3]
7. splice()
- Definition: Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
- Definition: Returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included) where begin and end represent the index of items in that array.
- Syntax: array.slice([start], [end])
- Example:
let arr = [1, 2, 3, 4, 5];
let slicedArr = arr.slice(1, 4);
console.log(slicedArr); // Output: [2, 3, 4]
26. isArray()
- Definition: Determines whether the passed value is an Array.
- Syntax: Array.isArray(value)
- Example:
let arr = [1, 2, 3];
console.log(Array.isArray(arr)); // Output: true
27. fill()
- Definition: Fills all the elements of an array from a start index to an end index with a static value.
- Syntax: array.fill(value[, start[, end]])
- Example:
let arr = [1, 2, 3, 4, 5];
arr.fill(0, 2, 4);
console.log(arr); // Output: [1, 2, 0, 0, 5]
28. keys()
- Definition: Returns a new Array Iterator object that contains the keys for each index in the array.