cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
cchicken
Level: Power Up

How to remove the last element of an array?

How would a compose an output to remove the last element of an array? My specific use case would be to remove an extension from a file name..

 

For example, I have a file name called: this.is.a.test.txt

Desired output: this.is.a.test

 

Thanks!

4 REPLIES 4
Julien2
Level: Powered On

Re: How to remove the last element of an array?

Hi @cchicken ,

 

This expression might help you:

substring(outputs('Compose'),0,sub(length(outputs('Compose')),4))

I hope it helps!

Regards,

Julien 

cchicken
Level: Power Up

Re: How to remove the last element of an array?

@Julien2 

 

I think this works. Can you briefly explain how this works? 

 

Thank you!

Julien2
Level: Powered On

Re: How to remove the last element of an array?

Hi @cchicken ,

 

The substring function allows extracting part of a string. I have specified where to start at position 0 and how many characters I want.
To find how many characters to take, I have used the length expression to give me the string length for the result.

 

If I have answered your question, please mark your post as Solved.

Thank you.

DeepakS
Level 8

Re: How to remove the last element of an array?

Hi @cchicken 

 

As @Julien2  suggested you should use substring function achieve this, I would prefer to add on the solution is to get the length of the last element dynamically:

MyString is variable storing : this.is.a.test.txt (You can actually use any other string )

 

 
substring(variables('MyString'),0,lastIndexOf(variables('MyString'),'.'))
 
-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
firstImage

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors
Users online (5,403)