Languages
[Edit]
EN

TypeScript - shift array elements

0 points
Created by:
Imaan-Morin
1009

In this article, we would like to show you how to shift array elements in TypeScript.

Quick solution:

const letters: string[] = ['A', 'B', 'C', 'D'];
letters.shift(); // removes 'A' from letters array

console.log(letters); // [ 'B', 'C', 'D' ]

 

Practical example

The shift() method removes the first element from an array and returns that removed element, so you can use it later.

const letters: string[] = ['A', 'B', 'C', 'D'];
const shifted: string = letters.shift(); // shifts 'A' from letters array to shifted const

console.log(letters); // B,C,D
console.log(shifted); // A

Output:

[ 'B', 'C', 'D' ]
A

See also

  1. JavaScript - shift array elements 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join