π Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
π Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
Syntax
arr.push(element1[, ...[, elementN]])
Example 1: Simple Array.push() method example
var animals = ['pigs', 'goats', 'sheep'];
console.log(animals.push('cows'));
console.log(animals);
animals.push('chickens');
console.log(animals);
4
["pigs", "goats", "sheep", "cows"]
["pigs", "goats", "sheep", "cows", "chickens"]
Example 2: Adding elements to an array
var sports = ['soccer', 'baseball'];
var total = sports.push('football', 'swimming');
console.log(sports);
console.log(total);
["soccer", "baseball", "football", "swimming"]
4
Comments
Post a Comment
Leave Comment