Access Array Elements from Any Side in JavaScript | JavaScript New Array Method Tutorial

preview_player
Показать описание
Access Array elements from left or right side, by using array length or without using array length. There is a new Array AT method in JavaScript that simplifies accessing Array elements from end of Array. Array is a variable that can hold more than one value. Simply it's a list of items. We can take a variable with few elements and look into JavaScript Arrays and JavaScript Array Methods. We will also learn JavaScript Array new method. You will learn new things in this JavaScript array tutorial.

Here is an Array called items holding bunch of numbers
const items = [1, 2, 3, 4]
We can also take strings instead of numbers
const items = ['Apple', 'Orange', 'Peach', 'Grapes']

I can access elements in this array by using index number.
Array index starts with zero.
I will type items zero to access first element in array.

items[0]
items[1]
items[2]
items[3]

What if I want to access last element in array?
For that I will need to know length of Array (array length is number of array elements).
This would give me last item in Array.

Access second last element
This would give me 3.

To access elements from left to right we can also use at method.

The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.

We can access elements from end without calculating length of Array by using at method. This is called Relative Indexing Method that is new feature in JavaScript. Relative indexing via negative indices is a feature that enjoys popularity in other languages like Python.

-1 means the last element

So Array at method simplifies things a little bit where we do not have to find length of Array to access elements from the end.

✅ How To Hide / Protect JavaScript Code - Techniques and Tools
✅ React JS UNDEFINED Solution | Reactjs Learning | Learn ReactJS & JavaScript Debugging Fast
✅ Calculate Sum or Total from Values in Array & Array Object | Learn JavaScript | Reduce Method
✅ Get URL Parameters in JavaScript | URLSearchParams
✅ DIV to PDF, Iframe to PDF using JavaScript Only (with CSS & Images Support)
✅ How To UnMinify JavaScript Minified Files Easily | Decrypt Complex JavaScript Code
✅ Toggle Class in Vanilla JavaScript | Learn JavaScript
✅ How to Execute a JavaScript File by using NPM
✅ Get User's Location (Country, State, City) with Free Unlimited API Access | PHP & JavaScript
✅ Replace jQuery with Vanilla JavaScript Code Easily | jQuery vs JavaScript
✅ Toggle in Vanilla JavaScript
✅ MINIFY JAVASCRIPT FILES & FOLDERS in Multiple Ways (Command Line & Code Editor)
✅ JavaScript vs jQuery | Difference between JavaScript and jQuery
✅ JavaScript Variable Redeclare & Reassign | VAR vs LET vs CONST | Practical Examples

Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT

#JavaScript #JS #Array #ArrayMethod #ArrayAt #JavaScriptArray #ArrayMethods #WebStylePress #webdevelopment
Рекомендации по теме