declare array in javascript
var cars = [
"Saab",
"Volvo",
"BMW"
]; //create array
var things = ["banana", "car", "computer"];
//access array(starts at 0)
things[0]
//iterate through an array
for (var i = 0; i < things.length; i++) {
things[i]
}var cars = ["Saab", "Volvo", "BMW"];
//single array declaration
var car1 = "Saab";
var car2 = "Volvo";
var car3 = "BMW";
//one line
var cars = ["Toyota", "Jeep", "BMW"];
//multiple lines
var cars = [
"Toyota",
"Jeep",
"BMW"
];// Initializing while declaring
var house = ["1BHK", "2BHK", "3BHK", "4BHK"];
// Initializing after declaring
house[0] = "1BHK";
house[0] = "2BHK";
house[0] = "3BHK";
house[0] = "4BHK";
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Also in JavaScript:
- js script
- javascript random number
- cordova load javascript without cache
- take a screen shot of a image within a div using js
- javascript int values
- string to boolean javascript
- return an array of strings from an array of objects js
- install node js 14
- odoo submit form using js and display data
- javascript get same elments from multiple arrays
- javascript write to text file
- iterate object js
- onclick timer javascript
- simple return data jquery
- Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied
- dropdown option selection change event in jquery
- javascript get url
- how to set up a success message show up if form is submitted in react hooks
- device width javascript
- RFC8259 json
- ant design react
- sort array by string length javascript
- date.parse string to javascript
- arrow function in javascript