JavaScript Arrays Crash Course | Master JavaScript Arrays



JavaScript Arrays Crash Course | Master JavaScript Arrays

JavaScript Arrays Crash Course | Master JavaScript Arrays

Arrays are one of the most fundamental building blocks of every popular and practical programming language. In this video I am going to cover everything that you need to know about, and understand arrays in JavaScript.

– What is an Array in JavaScript
Array is special variable that can hold a list of values. In JavaScript, a variable can hold a value. This single value can be a number or string and more. But when we need to store multiple values in a variable, array can be used. This set of values is an array, stored in variable called name or identifier declared by using let keyword.

– Why do we need an Array?
Lets say fruit1, fruit2, fruit3 are three variables holding same type of items. We can use one variable named as fruits and store these items in it. That is why we use Arrays. To store multiple values in a single variable. To avoid declaring multiple variables where we can use one. So array is used to store multiple values in a single variable. Or you can say that Array has list of items.

Array can store different data types like numbers, strings, boolean values (like true and false), objects, and so on.

– Test a variable if it holds array or not
Array isArray can tell if something is array or not. True means, it’s an Array.

– Find index of an element in an array
indexOf can tell index of item in array.

– Arrays are special type of objects.
typeof array shows that array type is object.

– Array has properties and methods.
Length is one of Array’s property. Empty array length is zero. Array length property shows how many items are in array.

– How to Create Array in JavaScript?
To create an array in JavaScript we open and close a square bracket. This array is an empty array. It has got no items inside it. We can create a variable and store this array in it. Empty array is undefined. It is declared but it has no value or item. So it’s undefined. But we created an array. Even though it’s an empty array. We can add items in array separated by commas.

This method of creating array is called ‘Array Literal method’.
We can also create array by using ‘Array Constructor’.
new Array()

It will also create an undefined array because it’s empty.
We can add values in it.

In arrays, list of items is stored inside square brackets. Each item is separated by a comma in the list. It’s common to declare array with const keyword. But you can use let as well. CONST can not be redeclared or reassigned but it allows you to add or delete values.

– How to Add Items in Array in JavaScript
We can add items in array by using push method in array. Array push will add item at the end of array. If you want to add item at starting position. Use unshift array method. Pushing values in an array that has been declared using const keyword is not re-assigning values to const. And this can be a good JavaScript Interview Question. You can use const keyword to declare array and change items in it.

– How to Replace Items in Array in JavaScript
We can target item index to change items or add new items in array.

– Get Values of Array in JavaScript
We can access values or items of array by using item index number. Array index starts with zero. If item does not exist on index being used, it will be undefined.

– Create Nested Array in JavaScript
Array can take any data type. You can add objects inside array to create nested array.

– Array Methods
There are many array methods like shift, pop, unshift, reverse, push, map and more. To reverse elements order use reverse method. To map through elements and get a new array use map method. You can use array methods to apply several changes to items or get a different result without changing original array depending on requirement.
Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT

Channel: https://www.youtube.com/webstylepress
Website: https://www.webstylepress.com
FaceBook: https://www.facebook.com/webstylepress
Twitter: https://twitter.com/webstylepress
GitHub: https://github.com/webstylepress
#WebStylePress #CrashCourse #Arrays #Array #JavaScript #JS #WebDevelopment #programming

Comments are closed.