An array in JavaScript is a versatile data structure used to store multiple values in a single variable. Arrays can hold various data types, including numbers, strings, and Boolean values.
To create an array, you start with an opening square bracket [, list your values separated by commas, and end with a closing square bracket ].
For example:
var arrayName = ['labw3', 235, true];
In this example, the array contains three different data types: a string ('labw3'), a number (235), and a Boolean (true).
Here are some key points about arrays in JavaScript:
- String Values: Enclose string values in single or double quotes.
var stringArray = ['apple', "banana"];
- Numbers and Booleans: Numbers and Boolean values do not require quotes.
var mixedArray = [123, false, 3.14];
Arrays are a fundamental part of JavaScript, providing a way to organize and manipulate collections of data efficiently.
No comments:
Post a Comment