THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
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
This example shows how to
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"
This example shows
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; } [];
This example shows
var arrayStrings = new Array("one", "two", "there", "four");
console.log(arrayStrings[arrayStrings.length-1] );
console.log(arrayStrings.pop() );
Output:
four
four
This example shows
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
🧮 Tags
Recent posts
Puppeteer Login Test example How to convert Double to Integer or Integer to double in Dart| Flutter By Example Best ways to fix 504 gateway time out in nodejs Applications Fix for Error No configuration provided for scss Multiple ways to List containers in a Docker with examplesRelated posts