slice()
Returns a shallow copy of a portion of an array.
Example:
let fruits = ['Apple', 'Banana', 'Mango', 'Orange'];
let citrus = fruits.slice(2, 4);
console.log(citrus); // Output: ['Mango', 'Orange']
concat()
Merges two or more arrays.
Example:
let fruits = ['Apple', 'Banana'];
let moreFruits = ['Mango', 'Orange'];
let allFruits = fruits.concat(moreFruits);
console.log(allFruits); // Output: ['Apple', 'Banana', 'Mango', 'Orange']
flat()
Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
Example:
let nestedArray = [1, [2, [3, [4]], 5]];
let flatArray = nestedArray.flat(2);
console.log(flatArray); // Output: [1, 2, 3, [4], 5]
join()
Joins all elements of an array into a string.
Example:
let fruits = ['Apple', 'Banana', 'Mango'];
let joined = fruits.join(', ');
console.log(joined); // Output: 'Apple, Banana, Mango'