# Frequently Used Array Examples Javascript|Typescript In this blog post, We are going to learn Frequently used Array Examples in typescript and javascript

The array is a collection of elements/objects stored under one name. The size of the array is fixed. Developers must learn Array examples in typescripts.

You can check my post on Array Sort-Object Examples and Javascript Add,Delete from Array

Following is a list of frequently used array examples

## How to remove an element or object from the Array

This example shows how to

• Delete / remove element from an array using Array.prototype.splice function
• First find an index of an element in an array using findIndex() function
• remove element from array using splice() function
``````var arrayStrings = new Array("one", "two", "there", "four");
var deleteElement = "one";
let index = this.arrayStrings.findIndex((d) => d === deleteElement);
this.arrayStrings.splice(index, 1);
console.log(arrayStrings);``````

Output:

``````0: "two"
1: "there"
2: "four"``````

## How to Create a Statically typed array of functions or callbacks in typescript

This example shows

1. How to Create an array of interfaces
2. How to create a Type array of callbacks or functions

First Create a named function of an interface that accepts strings and returns a void Create an array of interfaces

``````interface MyInterface {
(name: string): void;
}
var mycallback: MyInterface[] = [];
console.log(mycallback);``````

Or We can also use a typed array literal syntax for creating an array of functions

``var myNewFunction: { (name: string): void }[];``

## How to retrieve the last element or object from an array in Javascript?

This example shows

• the last element of an array using an array.length-1 function
• How to find the length of an array using Array.length-1 element
• Get the Last element of an array | array.pop() method
``````var arrayStrings = new Array("one", "two", "there", "four");
console.log(arrayStrings[arrayStrings.length - 1]);
console.log(arrayStrings.pop());``````

Output:

``````four;
four;``````

## How to create a Static array in typescript class

This example shows

1. Create a Static private array of a class
2. the getSize method returns the static array size using the length function
``````class MyClass {
private static stringArray: string[] = ["one", "two", "three","four"];
getSize(): number {
return MyClass.stringArray.length;
}
}
var myobject = new MyClass();
console.log(myobject.getSize());``````

Output:

``3;``
{"ft_lang_label":"__label__en","ft_lang_prob":0.55853915,"math_prob":0.69881785,"size":2434,"snap":"2023-40-2023-50","text_gpt3_token_len":550,"char_repetition_ratio":0.1563786,"word_repetition_ratio":0.02710027,"special_character_ratio":0.23746918,"punctuation_ratio":0.1554054,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9804445,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-06T01:00:35Z\",\"WARC-Record-ID\":\"<urn:uuid:fa233813-55f2-4be7-9e23-bf971f0bc761>\",\"Content-Length\":\"115219\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:565a5c93-afe0-40b8-be96-11ca5f8054b3>\",\"WARC-Concurrent-To\":\"<urn:uuid:8f4a5e87-a81f-44b2-8fd6-72c33e8fb877>\",\"WARC-IP-Address\":\"172.67.196.157\",\"WARC-Target-URI\":\"https://www.cloudhadoop.com/2018/09/frequently-used-array-examples.html\",\"WARC-Payload-Digest\":\"sha1:QLBEXCWEQBS5EYGWFJFRC7JYRPERZO4U\",\"WARC-Block-Digest\":\"sha1:7DE4LQ6GEL3YVDTUTCVUFBNMQXANW5UN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100575.30_warc_CC-MAIN-20231206000253-20231206030253-00525.warc.gz\"}"}