Append a value in an array through JavaScript

How to add or append values ​​to an array via JavaScript?
Last updated:7/20/2021 1:46:49 AM

1 Answers

Ethan Karla
Ethan Karla

In JavaScript if you want to add a value to an array you can use the function array push. You can understand this method more well if you learn it with the help of an example :

<!DOCTYPE html>

    <p id='demo'></p>
        const cars = ['BMW', 'Audi', 'Ferrari', 'Bentley'];
        cars.push('Rolls Royce');
        document.getElementById('demo').innerHTML = cars;

Hope this code will be helpful for you.

Happy Coding!