xxxxxxxxxx
//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]);
}
xxxxxxxxxx
//create an array:
let colors = ["red","blue","green"];
//you can loop through an array like this:
//For each color of the Array Colors
for (color of colors){
console.log(color);
}
//or you can loop through an array using the index:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
xxxxxxxxxx
//create an array
let numbers = [ 11 , 13 , 15 , 17]
//you can use loop like this
for(let i = 0;i<numbers.length;i++) {
console.log(numbers[i])
}
xxxxxxxxxx
const array = [1, 2, 3, true, null, undefined];
console.log(array);
// expected output
// 1, 2, 3, true, null, undefined
Sostituire Items in posizioni specifiche
xxxxxxxxxx
let arr = ["Ciao", "da", "Francesco", "Sciuti"];
arr.splice(0, 2, "io", "sono");
console.log(arr) // output: ["io", "sono", "Francesco", "Sciuti"];
xxxxxxxxxx
// Match one d followed by one or more b's followed by one d
// Remember matched b's and the following d
// Ignore case
const myRe = /d(b+)(d)/i
const myArray = myRe.exec('cdbBdbsbz')
xxxxxxxxxx
//An array is a list of thing, you can add as many things as you want
var food = ["cake", "apple", "Ice-Cream"]
//You can use Math.Random to pick a random number
//from one to the length of the array
var Number = [Math.floor(Math.random() * food.length)]; // get a random number
//then we can console.log the random word from the array
console.log(logammounts[woodloot])
//You can also create an array, then provide the elements:
Example
const food = [];
food[0]= "cake";
food[1]= "apple";
food[2]= "Ice-Cream";