DEV Community

Mehedi hasan
Mehedi hasan

Posted on

ES6? Array methods.

Array. The (of) method generates an example of a new array from a variable number argument, regardless of the number or type of argument.

Converts and returns an array-like object or list (such as argument, novelist, DOMTokenList (used by classlist),

NamedNodeMap (used by attribute property)) to a new array ();
The use-case is when you can't write a literal because you are passing a function-that-constructs as a funerary, and the eventual caller may pass only one number arg, or several args. In that case, Array will not do the right thing in the one-number-arg case.

The find () method executes a function for each array element. If no component is found, the find () method returns indefinitely. The find () method does not perform functions for empty elements.

The findIndex () method provides an index of the first elements of an array that satisfies a given test function. Otherwise, it returns -1

Array.keys( ) Returns only the key of the array element which is currently being indicated by the internal pointer
For Example:
var A = [ 5, 6, 10 ];
var iterator = A.keys()
for (let key of iterator) {
document.write(key + ' ');
}
Array.values() The function is a built-in JavaScript function used to return a new array iterator object that contains the value of each index in the array. For Example:
var array = [ 'a', 'c', 'n' ];
var iterator = array.values();
for (let elements of iterator) {
console.log(elements);
}
Output:

a,c,n

The fill () method converts all elements of an array to a static value example:
const array1 = [1, 2, 3, 4];

console.log(array1.fill(0, 2, 4));
console.log(array1.fill(5, 1));
console.log(array1.fill(6));
out put
Array [1, 2, 0, 0]
Array [1, 5, 5, 5]
Array [6, 6, 6, 6

Top comments (0)