how to use .push javascript code example

Example 1: add item to list javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi"); // Fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];

Example 2: pushing to an array

array = ["hello"]
array.push("world");

console.log(array);
//output =>
["hello", "world"]

Example 3: javascript add item to list

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");

Example 4: push javascript

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

Example 5: .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) ;

Tags:

Java Example