add array js code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 2: js array add element
array.push(element)
Example 3: javascript array add
let yourArray = [1, 2, 3];
yourArray.push(4);
Example 4: how to append objects to javascript lists ?
var studentList = ['Jason', 'Samantha', 'Alice', 'Joseph'];
studentList.push('Jacob');
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) ;
Example 6: add item to array javascript
const arr1 = [1,2,3]
const newValue = 4
const newData = [...arr1, obj]