Apu
October 03, 2022 .
#Javascript
.
#Q&A
❌
How do you write an array in JavaScript?
Creating an array in JavaScript is as easy as cutting a cake.
Array Syntax:
const array_name = [item1, item2,item3,...];
Use an array to store more than one value.
- array_name : we can give the array any name according to our choice.
- Inside the [ ] square bracket, we can store more than one value.
[ "Red", "Blue", "Green", "Yellow" ]
- To store a string in an array, we must use the double or single quote.
- We don't need to use any quote to store a number.
[ 7, 26, 478, 5 ]
Break and new line are not important.
Access an array element.
We can access an array element by referring to the index number.
const colors = ["Red", "Blue", "Green", "Yellow", "Pink"]
Using the colors[0] , we can access the first element of the above array.
save
listen
AI Answer
How do you write an array in JavaScript?
0
Creating an array in JavaScript is as easy as cutting a cake. Array Syntax: const array_na…
asked
Apu
0 answers
2915
Creating an array in JavaScript is as easy as cutting a cake. Array Syntax: const array_na…
Answer Link
answered
Apu