Array methods

  • Array from() Method: It converts array-like or iterable objects into a new array with optional mapping function.
  • Array keys() Method: It provides an iterator for array indices, allowing iteration over keys/indices in an array.
  • Array find() Method: It locates and returns the first array element satisfying a provided condition.
  • Array findIndex() Method: It retrieves the index of the first array element satisfying a given condition.

Example: In this example we are using the above mentioned methods one by one.

Javascript




const languages = ["HTML", "CSS", "JavaScript", "React.js"];
  
// Using Array.from() to create a new array of lengths
const lengths = Array.from(languages, lang => lang.length);
console.log(lengths); // Outputs: [4, 3, 10, 7]
  
// Using Array.keys() to iterate over array indices
for (const index of languages.keys()) {
    console.log(`Index ${index}: ${languages[index]}`);
}
  
// Using Array.find() to find the first language
// with length greater than 5
const longLanguage = languages.find(lang => lang.length > 5);
console.log(longLanguage); // Outputs: "JavaScript"
  
// Using Array.findIndex() to find the index of "React.js"
const reactIndex = languages.findIndex(
    lang => lang === "React.js");
      
console.log(reactIndex); // Outputs: 3


Output

[ 4, 3, 10, 8 ]
Index 0: HTML
Index 1: CSS
Index 2: JavaScript
Index 3: React.js
JavaScript
3

JS 2015 or ECMAScript 6 (ES6)

JS 2015 (ES6) also known as ECMAScript 6 (ES6), ECMAScript 6 (ES6) is a significant update to JavaScript, introducing arrow functions, classes, template literals, let and const for variable declaration, enhanced object literals, destructuring, and more modern features for better code organization and readability.

Similar Reads

ECMAScript 6 (ES6) New Features

...

Method 1: let and const keyword

JavaScript let is a keyword used to declare variables in JavaScript that are block scoped. JavaScript const for declaring variables with immutable values, enhancing code stability and readability....

Method 2: Arrow Function

...

Method 3: Spread Operator

Arrow functions were introduced in the ES6 version.Arrow functions are anonymous functions i.e. functions without a name and are not bound by an identifier. Arrow functions do not return any value and can be declared without the function keyword. They are also called Lambda Functions....

Method 4: for/of Loop

...

Method 5 : Map Objects

The Spread operator allows an iterable to expand in places where 0+ arguments are expected. It is mostly used in the variable array where there is more than 1 value is expected....

Method 6: Set Objects

...

Method 7: Promises

The for…of loop in JavaScript iterates over iterable objects, like arrays, strings, for concise and readable element access and iteration....

Method 8: ES6 Symbol

...

Method 9: Default Parameters

In JavaScript, a Map object holds key-value pairs, allowing any type of key, unlike objects. It maintains order and provides methods for manipulation and retrieval....

Method 10: Rest Parameter

...

Method 11: String.includes() Method

In JavaScript, a Set object stores unique values of any type. It ensures uniqueness, provides methods for manipulation, and doesn’t allow duplicate values within the set....

Method 12: String.startsWith() and String.endsWith() Methods

...

Method 13: Array methods

Promises in JavaScript manage asynchronous operations, representing eventual results or errors. They simplify handling async code with methods like .then(), .catch(), and allow chaining....

Method 14: New Math Methods

...

Method 15: New Number Methods

ES6 Symbol is a unique, immutable data type used as object property keys, ensuring uniqueness. It’s primarily for internal/private use, avoiding unintended clashes in properties....

Method 16: New Global Methods

...

Method 17: Object Entries

It is used to give the default values to the arguments, if no parameter is provided in the function call....