How to add new element to array in JavaScript

2 Answers

0 votes
let arr = ["JavaScript", "PHP", "C"];

console.log(arr);

arr.push("C++");

console.log(arr);


  
    
    
/*
run:
    
["JavaScript", "PHP", "C"]
["JavaScript", "PHP", "C", "C++"]
    
*/

 



answered Jan 25, 2021 by avibootz
0 votes
let arr = ["JavaScript", "PHP", "C"];

console.log(arr);

arr.unshift("C++", "Python");

console.log(arr);


  
    
    
/*
run:
    
["JavaScript", "PHP", "C"]
["C++", "Python", "JavaScript", "PHP", "C"]
    
*/

 



answered Jan 25, 2021 by avibootz
...