how to make and add to an array in javascript code example
Example 1: javascript append element to array
var colors= ["red","blue"];
colors.push("yellow");
Example 2: javscript append item from array
let foo = ['oop','plop','copo'];
foo.push("plop");
Example 3: javascript add element to array
const langages = ['Javascript', 'Ruby', 'Python'];
langages.push('Go'); // => ['Javascript', 'Ruby', 'Python', 'Go']
const dart = 'Dart';
langages = [...langages, dart]; // => ['Javascript', 'Ruby', 'Python', 'Go', 'Dart']
Example 4: how to make and add to an array in javascript
var arrayExample = [53,'Hello World!'];
console.log(arrayExample) //Output =>
[53,'Hello World!']
//You can also do this
arrayExample.push(true);
console.log(arrayExample); //Output =>
[53,'Hello World!',true];