initialize array javascript

JavaScript
//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]);
}var cars = ["Saab", "Volvo", "BMW"];
 The JavaScript filter() method has several components to its syntax.

newArray = initialArr.filter(callback);
newArray: you name the array that will consist of the filtered elements.
initialArr: the name of the original array.
callback: the method applied to the initialArr.
The callback can have three arguments as well:

element: the current element of the array.
index: the index number of the currently handled value.
array: the original array.
Therefore, the full syntax of the JavaScript array filter function would look like this:

newArray = initialArr.filter(callback(element, index, array));// Initializing while declaring 
// Creates an array having elements 10, 20, 30, 40, 50 
var house = new Array(10, 20, 30, 40, 50); 
  
//Creates an array of 5 undefined elements 
var house1 = new Array(5); 
  
//Creates an array with element 1BHK 
var home = new Array("!BHK"); 

Source

Also in JavaScript: