In this Power Automate tutorial, we will see how to remove an item from an array in Power Automate.
Here, I will show different examples related to various topics below:
- How to remove the last item from an array in Power Automate
- Remove the first item from an array in Power Automate
- How to remove a specific item from an array in Power Automate
- How to remove empty items from an array in Power Automate
Remove an item from an array in Power Automate
Here we will see how to remove the item from an array using Power Automate
To remove the item from an array using Power Automate skip() method.
The skip method in Power Automate is used to remove the items from the front.
Step 1: Log in to Power Automate, and click on +Create -> select the Instant Cloud flow.
Provide the flow name, and select the Manually trigger a flow. Then click on Create.
Now Manually trigger a flow is added to the flow.
Step 2: Now, click on the +New step, and select the Initialize variable action. Then provide the below information:
- Name: provide the name of the variable
- Type: Select the type as Array
- Value: Provide the below array
[
{
"id": 1,
"name": "Item 1",
"price": 10.99
},
{
"id": 2,
"name": "Item 2",
"price": 19.99
},
{
"id": 3,
"name": "Item 3",
"price": 5.99
},
{
"id": 4,
"name": "Item 4",
"price": 7.99
}
]
Step 3: Now we will remove the item from an array, so, click on the +New step -> select Compose action. Then provide the below information
- Inputs: Provide the below expression as an inputs
skip(variables('Array'), 1)
Step 4: Now run the flow manually, you can see the output of compose action, and the first item has been removed.
This is how to remove an item from an array in Power Automate.
Remove the last item from an array in Power Automate
Here we will see how to remove the last item from an Array using Power Automate
So here we will use the above array, and we will remove the last item from this array using take, length, and add methods.
Here is how we can implement it:
- First, we will calculate the length of an array using length().
- Then we will add -1 to the length of the original array using the add method
- Then we will use the take(), which will take the whole array and extract all items except the last one.
Step 1: In Power Automate, click on +Create and then select Instant cloud flow.
Then provide the flow name and select Manually trigger a flow. Click on Create.
Now Manually trigger a flow is added to the flow page.
Step 2: Now, click on the +New step, and select the Initialize variable action. Then provide the below information:
- Name: Provide the name of the variable
- Type: Select the type as Array
- Value: Provide the below array
[
{
"id": 1,
"name": "Item 1",
"price": 10.99
},
{
"id": 2,
"name": "Item 2",
"price": 19.99
},
{
"id": 3,
"name": "Item 3",
"price": 5.99
},
{
"id": 4,
"name": "Item 4",
"price": 7.99
}
]
Step 3: Now we will remove the last item from an array, so click on the +New step -> select Compose action. Then provide the below information:
- Inputs: Provide the below expression:
take(variables('Array'),add(length(variables('Array')),-1))
Step 4: Now run the flow manually, and you can see the result, the last item is removed from an array using Power Automate.
This is how to remove the last element from an array in Power Automate
Remove the first item from an array in Power Automate
Here we will see how to remove the first 2 items from an array using Power Automate.
For example, we have an array [1,2,3,4] so, we will create a flow that will reverse the array [4,3,2,1] and then remove the last 2 items i.e. 2, 1. Then it will return [4,3], and after that, we will reverse the result array and the final output is [3,4]
Step 1: Now, create an instant cloud flow, then provide the flow name and select manually trigger a flow. Then click on Create.
Now you can see Manually trigger a flow is added to the page.
Step 2: Next click on the +new step -> select Initialize variable action. Then provide the below information:
- Name: Provide the name of the variable
- Type: Select the type as Array
- Value: Provide the below array
[
{
"id": 1,
"name": "Item 1",
"price": 10.99
},
{
"id": 2,
"name": "Item 2",
"price": 19.99
},
{
"id": 3,
"name": "Item 3",
"price": 5.99
},
{
"id": 4,
"name": "Item 4",
"price": 7.99
}
]
Step 3: Next click on the +New step -> select Compose action -> then provide the below information.
- Inputs: Provide the below expression
reverse(variables('Array'))
Similarly, create two more compose action, and then provide the information as Inputs.
Compose -remove the item
take(outputs('Compose_-reverse_the_array'),add(length(outputs('Compose_-reverse_the_array')),-1))
Compose – result
reverse(outputs('Compose-_remove_the_item'))
Step 4: Now test the flow manually and you can see the result, first 2 items is removed from an array using Power Automate.
This is how to remove the first item from an array in Power Automate.
Remove a specific item from an array in Power Automate
Here we will see how to remove specific items from an array of objects using Power Automate.
For example, we have array [1,2,3,4], so here we will create a flow that will remove 2 from an array and return [1,3,4] in Power Automate.
Step 1: Create an Instant cloud flow, then provide the flow name and select Manually trigger a flow in Power Automate. Then click on Create
Now Manually trigger a flow action is added to the flow page.
Step 2: Now, click on the +New step -> select Initialize variable action. Then provide the below information:
- Name: Provide the name of the variable
- Type: Select the type as Array
- Value: Provide the below array
[
{
"id": 1,
"name": "Item 1",
"price": 10.99
},
{
"id": 2,
"name": "Item 2",
"price": 19.99
},
{
"id": 3,
"name": "Item 3",
"price": 5.99
},
{
"id": 4,
"name": "Item 4",
"price": 7.99
}
]
Step 3: Now we will remove the specific item, so, click on the +New step -> select Filter array action. Then provide the below information:
- From: Select the array variable from dynamic content.
- Choose a value: Provide the below expression:
@item()['id']
- Operator: Select the operator as is not equal to
- Choose a value: Provide the value as empty like the below screenshot.
Step 4: Now test the flow manually, and you can see the result, that id =2 is removed from the array.
This is how to remove a specific item from an array in Power Automate.
Remove empty items from an array in Power Automate
Here we will see how to remove empty items from an array of objects using Power Automate.
In this example, we will use the array of objects and we need to remove the items whose price value is empty.
Step 1: In Power Automate, select Instant cloud flow. Then provide the flow name, and select ‘Manually trigger a flow’. Then click on Create.
Now Manually trigger a flow is added to the flow page.
Step 2: Then click on the +New step and select Initialize variable action. Then provide the below information:
- Name: Provide the name of the variable
- Type: Select the type as Array
- Value: Provide the below array
[
{
"id": 1,
"name": "Item 1",
"price": ""
},
{
"id": 2,
"name": "Item 2",
"price": 19.99
},
{
"id": 3,
"name": "Item 3",
"price": ""
},
{
"id": 4,
"name": "Item 4",
"price": 7.99
}
]
Step 3: Next we will remove the item whose price column is empty, so click on the +New step -> select Filter array action. Then provide the below information:
- From: Select the array variable from dynamic content.
- Choose a value: Provide the below expression:
item()['price']
- Operator: Select the operator as is not equal to
- Choose a value: provide the value as empty like the below screenshot.
Step 4: Now run the flow manually, and you can see the items removed, whose price value is empty.
This is how to remove an empty item from an array using Power Automate.
Conclusion
In this Power Automate tutorial, we saw how to remove items from an array using Power Automate. Also, we cover 5 different examples. These are:
- Power Automate remove the item from an array
- Power Automate remove the last item from an array
- Power Automate remove the first item from an array
- Power Automate remove a specific item from an array
- Power Automate remove the empty item from an array
You may also like:
- How to read a text and count its occurrence from a docx file in Power automate?
- Add Hyperlinks to SharePoint List Items Using Power Automate
- Power Automate error: Cannot find the resource for the request addroleassignhments
- Add Comments to SharePoint list items using Power Automate
- Create SharePoint lists from JSON using Power Automate
- How to check if an array contains value using Power Automate?
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.