DEV Community

Mahamud Pino
Mahamud Pino

Posted on

JavaScript Topic

*JavaScript Shift : *

In JavaScript this method removes the first element from an array and returns the removed element. Shift() method mostly used to sort an array.

Syntax of JavaScript Shift Function:

Image description

Example:
Image description

Here this code removes the first word ‘hasan’ from the array.

*JavaScript Slice: *

This function returns a slice object. This method returns a shallow copy of a portion of an array into a new array object selected from start to end.

Syntax of JavaScript Shift Function:
Image description

Example:
Image description
Here this code starts a slice from index 3 means (l) and ends index 10.

*JavaScript Spread Operator: *

This function allows an iterable to expand in places where 0+ arguments are expected. Mostly used in the variable array where there are more than 1 values are expected. In JavaScript we use it to copy the full array and add it with a new array.

Example:
Image description

In this code ‘tom’ will be added with a full ‘data’ array.

**

JavaScript Reduce:

**

The method executes a reducer function for array elements. The reduce() method returns a single value. Normally we can tell this function will add total value in a single value.

Example:

Image description

This code returns answer 6.

**

JavaScript template string:

**

This function is a powerful feature of ES6. It is mainly called Literals. It added two parts into a string. It is mainly used to connect multiple lines into a single line. Before the release of ES6 it was difficult to use but now we can do that very easily.

Example:
Image description

Top comments (0)