Access Array Elements from Any Side in JavaScript | JavaScript New Array Method Tutorial
Автор: WebStylePress
Загружено: 2022-03-04
Просмотров: 701
Описание:
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).
For that I would type items.length -1.
This would give me last item in Array.
items[items.length - 1]
Access second last element
items[items.length - 2]
This would give me 3.
items[items.length - 3]
items[items.length - 4]
To access elements from left to right we can also use at method.
items.at(0)
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.
items.at(1)
items.at(2)
items.at(3)
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.
items.at(-1)
-1 means the last element
items.at(-2)
items.at(-3)
items.at(-4)
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
• How To Hide / Protect JavaScript Code | Ja...
✅ React JS UNDEFINED Solution | Reactjs Learning | Learn ReactJS & JavaScript Debugging Fast
• How to Prevent TypeError Cannot Read Prope...
✅ Calculate Sum or Total from Values in Array & Array Object | Learn JavaScript | Reduce Method
• How to Find Sum of An Array of Numbers in ...
✅ Get URL Parameters in JavaScript | URLSearchParams
• Get URL Parameters in JavaScript | URLSear...
✅ DIV to PDF, Iframe to PDF using JavaScript Only (with CSS & Images Support)
• DIV to PDF, Iframe to PDF using JavaScript...
✅ How To UnMinify JavaScript Minified Files Easily | Decrypt Complex JavaScript Code
• How To UnMinify JavaScript Minified Files ...
✅ Toggle Class in Vanilla JavaScript | Learn JavaScript
• Toggle Class in Vanilla JavaScript
✅ How to Execute a JavaScript File by using NPM
• How to Run a JavaScript File using NPM
✅ Get User's Location (Country, State, City) with Free Unlimited API Access | PHP & JavaScript
• Get User Location (Country, State, City) w...
✅ Replace jQuery with Vanilla JavaScript Code Easily | jQuery vs JavaScript
• Replace jQuery with Vanilla JavaScript Cod...
✅ Toggle in Vanilla JavaScript
• Toggle in Vanilla JavaScript | Pure JavaSc...
✅ MINIFY JAVASCRIPT FILES & FOLDERS in Multiple Ways (Command Line & Code Editor)
• MINIFY JAVASCRIPT FILES & FOLDERS in Multi...
✅ JavaScript vs jQuery | Difference between JavaScript and jQuery
• JavaScript vs jQuery | Difference between ...
✅ JavaScript Variable Redeclare & Reassign | VAR vs LET vs CONST | Practical Examples
• VAR vs LET vs CONST | JavaScript Variable ...
Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT
Channel: / webstylepress
Website: https://www.webstylepress.com
FaceBook: / webstylepress
Twitter: / webstylepress
GitHub: https://github.com/webstylepress
#JavaScript #JS #Array #ArrayMethod #ArrayAt #JavaScriptArray #ArrayMethods #WebStylePress #webdevelopment
Повторяем попытку...

Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: