Arrays

They're like collections of variables that can even have different data types. or according to W3schools. An array is a special variable, which can hold more than one value at a time.

Example


// Initialize new array
var names = ['Roopak', 'Brooke', 'David'];
var years = new Array(1992, 1993, 1992);
console.log(names[2]);
console.log(names.length);

// Mutate array data
names[1] = 'Sarah';
names[names.length] = 'Ramesh';
console.log(names);

// Different data types in array
var john = ['Roopak', 'Kumar', 1992, 'Student', True];

roopak.push('blue');
roopak.unshift('Mr.');
console.log(roopak);

roopak.pop();
roopak.pop();
roopak.shift();
console.log(roopak);

click 'Check' to see the answer