javascript array object code example

Example 1: javascript array

//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]);
}

Example 2: how to make an array in javascript

var names = ["Sanjith", "Pranav", "Aadya", "Saharsh"]

Example 3: array of objects javascript

var widgetTemplats = [
    {
        name: 'compass',
        LocX: 35,
        LocY: 312
    },
    {
        name: 'another',
        LocX: 52,
        LocY: 32
    }
]

Example 4: javascript to array

Array.from("Hello"); // ["H", "e", "l", "l", "o"]

Example 5: array javascript

var familly = []; //no familly :(
var familly = new Array() // uncommon
var familly = [Talel, Wafa, Eline, True, 4];
console.log(familly[0]) //Talel
familly[0] + "<3" + familly[1] //Talel <3 Wafa
familly[3] = "Amir"; //New coming member in the family

Example 6: array javascript

special_dates = [];
special_dates.push(new Date('2021/02/12').getTime());
special_dates.push(new Date('2021/02/13').getTime());
special_dates.push(new Date('2021/02/14').getTime());

			
for (var i = 0; i < special_dates.length; i++) {
 console.log(special_dates[i]) ;
}

Tags:

Java Example