The Array method push() in Apps Script

Last updated: February 10, 2025

The Array method push() adds elements to the end of an array. It returns the new length of the array after the elements are added to it.

Syntax

array.push(element1, element2, …, elementN)

Parameters

The elements to be added to the array. These will be added to the end of the array.

Return value

The push() method returns the new length of the array after elements are added to it.

Example

The code below uses the push() array method to add two new elements to the array colors.

var colors = ["red", "blue", "green", "black", "orange", "purple"];
Logger.log(colors);
Logger.log(colors.length);
var newLength = colors.push("indigo", "violet");
Logger.log(colors);
Logger.log(newLength);

Output

[red, blue, green, black, orange, purple]

6.0

[red, blue, green, black, orange, purple, indigo, violet]

8.0

Conclusion

In this tutorial, you learned how to use the push() array method to add elements to the end of an array.

DISCLAIMER: This content is provided for educational purposes only. All code, templates, and information should be thoroughly reviewed and tested before use. Use at your own risk. Full Terms of Service apply.

Small Scripts, Big Impact

Join 1,500+ professionals who are supercharging their productivity with Google Sheets automation

Exclusive Google Sheets automation tutorials and hands-on exercises
Ready-to-use scripts and templates that transform hours of manual work into seconds
Email updates with new automation tips and time-saving workflows

By subscribing, you agree to our Privacy Policy and Terms of Service