// let arr_name, elemType[];
let list: number[] = [1, 2, 3];
// Generic array type, Array<elemType>:
let list: Array<number> = [1, 2, 3];
// If we have an array, we can define its type in TypeScript by using the notation type[].
let arrayType:string[] = [ 'hello', 'there' ]
// Similarly, an array of numbers could be defined like this:
let myNumbers:number[] = [ 1, 2, 3, 4 ];
let strings: string[] = ['Hello', 'World', '!']
const friends:string[] = ["Adil", "Abrar", "Anfal","Ashik"];
interface Movie {
title: string;
lengthMinutes: number;
}
// The array is typed using the Movie interface
var movies: Movie[] = [];
// Each item added to the array is checked for type compatibility
movies.push({
title: 'American History X',
lengthMinutes: 119,
production: 'USA' // example of structural typing
});
movies.push({
title: 'Sherlock Holmes',
lengthMinutes: 128,
});
movies.push({
title: 'Scent of a Woman',
lengthMinutes: 157
});
function compareMovieLengths(x: Movie, y: Movie) {
if (x.lengthMinutes > y.lengthMinutes) {
return -1;
}
if (x.lengthMinutes < y.lengthMinutes) {
return 1;
}
return 0;
}
// The array.sort method expects a comparer that accepts 2 Movies
var moviesOrderedLength = movies.sort(compareMovieLengths);
// Get the first element from the array, which is the longest
var longestMovie = moviesOrderedLength[0];
console.log(longestMovie.title); // Scent of a Woman
let arraytest: any[] = [1, 2, 3]
console.log(arraytest)
/*
Output: [1, 2, 3]
or try this
*/
console.log([1, 2, 3])// clever trick
let list: number[] = [1, 2, 3];
let myArray:string[] = ["your", "hello", "world"];
var alphas:string[];
alphas = ["1","2","3","4"]
console.log(alphas[0]);
console.log(alphas[1]);