js push add code example

Example 1: javascript array push

var SomeRandomArray = [];
SomeRandomArray.push("Hello, world!");

Example 2: javascript array push

let animals = ["dog","cat","tiger"];

animals.pop(); // ["dog","cat"]

animals.push("elephant"); // ["dog","cat","elephant"]

Example 3: push javascript

let fruit = ['apple', 'banana']
fruit.push('cherry')
console.log(fruit) // ['apple', 'banana', 'chery']

Example 4: javascript push

const animals = ['pigs', 'goats', 'sheep'];

const count = animals.push('cows');
console.log(count);
// expected output: 4
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]

animals.push('chickens', 'cats', 'dogs');
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows", "chickens", "cats", "dogs"]

Example 5: javascript array push

var fruits = [ "Orange", "Apple", "Mango"];

fruits.push("Banana");

Example 6: .push js

let monTableau2D = [
     ['Mark' , 'jeff' , 'Bill'] , 
     ['Zuckerberg' , 'Bezos' , 'Gates']
 ] ;
 monTableau2D[1].push('test') ; 
 console.log(monTableau2D) ;
              //////////////////
let monTableau = ['un', 'deux','trois', 'quatre'] ;
monTableau.push('cinq') ;
console.log(monTableau) ;

			///////////////////

let monTableauAssociatif = {
     'prenom' : 'Mark' ,
     'nom'    : 'Zuckerberg' , 
     'poste'  : 'Pdg de Facebook',

 } ;
 monTableauAssociatif['nationalite'] = 'Américaine' ;
 console.log(monTableauAssociatif) ;