Skip to main content

Command Palette

Search for a command to run...

Shift and Unshift Method In JavaScript

Updated
โ€ข1 min readโ€ขView as Markdown
Shift and Unshift Method In JavaScript
Y

An engineer by profession and a JavaScript Lover by heart.

First and foremost, I love writing code. Ever since writing my first program in C and manipulating it to produce the desired output. I believe in the power of programming to transform and improve the lives of people around the world.

My curiosity levels are as fresh as when I was a child. I believe in eternal learning and deliberate effort as they are the only way to become the smartest in the room. I am a good timekeeper, always willing to learn new skills and use them in real-life problems.

An ambitious individual with a desire to succeed. A Cricket fanatic. A student who likes to take risks and does not shy away from experimenting with various combinations in life. Striving to do a lot. Wish me good luck ๐Ÿ™๐Ÿผ

My primary interest is in Web Development and Mobile Application Development.

Tech Stack:- ReactJS, NextJS, NodeJS, MongoDB, GraphQL, Javascript Version Control:- Git, Gitlab

  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

More from this blog

Yash Mantri

20 posts

An engineer by profession and a JavaScript Lover by heart