Thursday, July 1, 2021

TypeScript - Arrays | Example | Demo

An array is a special type of data type which can store multiple values of different data types sequentially using a special syntax.
TypeScript supports arrays, similar to JavaScript. There are two ways to declare an array:

Array Methods
Method Description
pop() Removes the last element of the array and return that element
push() Adds new elements to the array and returns the new array length
sort() Sorts all the elements of the array
concat() Joins two arrays and returns the combined result
indexOf() Returns the index of the first match of a value in the array (-1 if not found)
copyWithin() Copies a sequence of elements within the array
fill() Fills the array with a static value from the provided start index to the end index
shift() Removes and returns the first element of the array
splice() Adds or removes elements from the array
unshift() Adds one or more elements to the beginning of the array
includes() Checks whether the array contains a certain element
join() Joins all elements of the array into a string
lastIndexOf() Returns the last index of an element in the array
slice() Extracts a section of the array and returns the new array
toString() Returns a string representation of the array
toLocaleString() Returns a localized string representing the array


Demo Example





No comments:

Post a Comment

How to build an Express and Node.js app with Typescript

  In this tutorial, you will learn how to set up a Node.js and Express project with Typescript and live auto-reloading. Note that this metho...