Add elements to an array to the second position

A simple example of adding elements to an array to the second position.
<!DOCTYPE html>
<html>
<head>
   
</head>
<body>

<script>
    
         var vehicles = ["Lamborghini", "Ferrari", "A-10 Thunderbolt", "F-16", "Mi-7", "T-34/85", "Titanic"];
    
            	 console.log("Vehicles before adding new elements = " + vehicles);
    
             vehicles.splice(2, 0, "AWACS", "MLRS", "Tornado");
    
            	 console.log("Vehicles after adding new elements = " + vehicles);
    
</script>

</body>
</html>

Responses

0 Replies