JavaScript Arrays 🚀
(A beginner's guide)
👇🧵
(A beginner's guide)
👇🧵
Don't forget to bookmarked it for future reference...
An array is an object that can store multiple values at once.
Example :
const words = ['hello', 'world'];
Here, words is an array. The array is storing 2 values.
Example :
const words = ['hello', 'world'];
Here, words is an array. The array is storing 2 values.
Ways to Create an Array
• We can create an array using two ways:
1. Using an array literal
The easiest way to create an array is by using an array literal [].
Example :
const array1 = ["code", "sleep"];
• We can create an array using two ways:
1. Using an array literal
The easiest way to create an array is by using an array literal [].
Example :
const array1 = ["code", "sleep"];
2. Using the new keyword
We can also create an array using JavaScript's new keyword.
Example :
const array2 = new Array("code", "sleep");
We can also create an array using JavaScript's new keyword.
Example :
const array2 = new Array("code", "sleep");
We can also store arrays, functions and other objects inside an array.
Example :
const newData = [
{'task1': 'exercise'},
[1, 2 ,3],
function hello()
{
console.log('hello')
}
];
Example :
const newData = [
{'task1': 'exercise'},
[1, 2 ,3],
function hello()
{
console.log('hello')
}
];
Access Elements of an Array
We can access elements of an array using indices (0, 1, 2 …).
Example :
const Arr = ['h', 'e', 'l', 'l', 'o'];
// first element
console.log(Arr[0]); // "h"
// second element
console.log(Arr[1]); // "e"
Note: Array's index starts with 0.
We can access elements of an array using indices (0, 1, 2 …).
Example :
const Arr = ['h', 'e', 'l', 'l', 'o'];
// first element
console.log(Arr[0]); // "h"
// second element
console.log(Arr[1]); // "e"
Note: Array's index starts with 0.
Here are the few arrays methods 👇
End thread 🧵
If you liked this thread:
-RT the first thread and share it with folks on Twitter.
-Follow @personalvipin for more such insightful threads.
Thanks for reading!
If you liked this thread:
-RT the first thread and share it with folks on Twitter.
-Follow @personalvipin for more such insightful threads.
Thanks for reading!
جاري تحميل الاقتراحات...