Better handling an array with method

65 views
Skip to first unread message

Ryuya

unread,
Jan 4, 2023, 9:29:48 PM1/4/23
to Google Apps Script Community
Hi there.
I hope you all stay safe.

The below photo is the example scripting to show what I would like to do.
In my scriptings, I often want to call a variable in different ways and times that I put an array on at the very beginning of the script .

As an example,  
I want to call "array" to output it on sheet A after using pop method (delete last element in an array).
I also want to call "array" to output it on sheet B after using shift method (delete first element in an array) .

I thought it could work as the scripting in the  below photo but not actually.

Would there be any better scripting?

Appreciate your support in advance. 

スクリーンショット 2023-01-05 11.19.37.png

Ed Sambuco

unread,
Jan 4, 2023, 10:09:03 PM1/4/23
to google-apps-sc...@googlegroups.com
Array and newArray point to the same array.

To copy to a new array

let newArray = array.splice();
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/bb0d81b1-310c-4657-8314-e24656e81962n%40googlegroups.com.

Ed Sambuco

unread,
Jan 5, 2023, 1:17:39 AM1/5/23
to google-apps-sc...@googlegroups.com
Oops .. I meant array.slice(),  Sorry 
..


On Wednesday, January 4, 2023, Ed Sambuco <esamb...@gmail.com> wrote:
Array and newArray point to the same array.

To copy to a new array

let newArray = array.splice();

On Wednesday, January 4, 2023, Ryuya <ryuya_...@tyomnl.net> wrote:
Hi there.
I hope you all stay safe.

The below photo is the example scripting to show what I would like to do.
In my scriptings, I often want to call a variable in different ways and times that I put an array on at the very beginning of the script .

As an example,  
I want to call "array" to output it on sheet A after using pop method (delete last element in an array).
I also want to call "array" to output it on sheet B after using shift method (delete first element in an array) .

I thought it could work as the scripting in the  below photo but not actually.

Would there be any better scripting?

Appreciate your support in advance. 

スクリーンショット 2023-01-05 11.19.37.png

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsubs...@googlegroups.com.

Ryuya

unread,
Jan 5, 2023, 2:41:39 AM1/5/23
to Google Apps Script Community
Thank you for your advice.
I will give it a try.

Appreciate you a lot.

Reply all
Reply to author
Forward
0 new messages