4. Arrays
📘 কনসেপ্ট (থিওরি)
টাইপস্ক্রিপ্টে অ্যারে টাইপ করার নির্দিষ্ট সিনট্যাক্স আছে।
[1, 2, 3] এর মতো একটি অ্যারের টাইপ নির্দিষ্ট করতে, আপনি number[] সিনট্যাক্স ব্যবহার করতে পারেন।
const names: string[] = ["Dylan", "John", "Alice"];
readonly কীওয়ার্ড অ্যারেকে পরিবর্তন হওয়া থেকে আটকাতে পারে।
const names: readonly string[] = ["Dylan"];
// names.push("Jack"); // Error: Property 'push' does not exist on type 'readonly string[]'.
💡 উদাহরণ
টাইপড অ্যারে:
const numbers: number[] = [1, 2, 3];
numbers.push(4);
// numbers.push("2"); // Error: Argument of type 'string' is not assignable to parameter of type 'number'.
console.log(numbers);
🎯 আপনার কাজ (প্র্যাকটিস)
"Apple" এবং "Banana" সম্বলিত স্ট্রিংয়ের একটি টাইপড অ্যারে
fruits তৈরি করুন। অ্যারেটি প্রিন্ট করুন।main.typescript
Loading...
OUTPUT
Run your code to see the output here...