जावास्क्रिप्ट ऐरे 0-इंडेक्स्ड हैं। इसका अर्थ है कि पहला एलिमेंट 0th पोजीशन पर है। अंतिम एलिमेंट length-of-array - 1th पोजीशन पर है। इसलिए हम इन एलिमेंट्स को एक्सेस कर सकते हैं:
arr[0] // पहला एलिमेंट arr[arr.length - 1] // अंतिम एलिमेंट उदाहरण के लिए, let arr = [1, 'test', {}, 'hello'] console.log(arr[0]) console.log(arr[arr.length - 1])
आउटपुट
1 hello