Shift and Unshift Method In JavaScript

Shift and Unshift Method In JavaScript

ยท

1 min read

  1. ๐—ฆ๐—ต๐—ถ๐—ณ๐˜ ๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ

The shift method is like the pop method, but it only works at the beginning of the array.

The shift method ๐—ฝ๐˜‚๐—น๐—น๐˜€ ๐˜๐—ต๐—ฒ ๐—ณ๐—ถ๐—ฟ๐˜€๐˜ ๐—ฒ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ผ๐—ณ๐—ณ of the given array and returns it.

This method will ๐—ฐ๐—ต๐—ฎ๐—ป๐—ด๐—ฒ ๐˜๐—ต๐—ฒ ๐—ผ๐—ฟ๐—ถ๐—ด๐—ถ๐—ป๐—ฎ๐—น ๐—ฎ๐—ฟ๐—ฟ๐—ฎ๐˜†.

Syntax: array.shift()

  1. ๐—จ๐—ป๐˜€๐—ต๐—ถ๐—ณ๐˜ ๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ

The unshift method is like the push method, but it only works at the beginning of the array.

The unshift method ๐—ฎ๐—ฑ๐—ฑ๐˜€ ๐—ป๐—ฒ๐˜„ ๐—ถ๐˜๐—ฒ๐—บ๐˜€ ๐˜๐—ผ ๐˜๐—ต๐—ฒ ๐—ฏ๐—ฒ๐—ด๐—ถ๐—ป๐—ป๐—ถ๐—ป๐—ด of an array and returns the new length.

This method will ๐—ฐ๐—ต๐—ฎ๐—ป๐—ด๐—ฒ ๐˜๐—ต๐—ฒ ๐—ผ๐—ฟ๐—ถ๐—ด๐—ถ๐—ป๐—ฎ๐—น ๐—ฎ๐—ฟ๐—ฟ๐—ฎ๐˜†.

Syntax: array.unshift(item1, item2, ..., itemx)

๐—˜๐˜…๐—ฎ๐—บ๐—ฝ๐—น๐—ฒ ๐Ÿ‘‡

carbon (2).png

ย