# Remove a item from the list

**URL:** <https://community.hubspot.com/t/remove-a-item-from-the-list/78946>\
**Category:** CMS Development\
**Tags:** professional\
**Created:** [April 8, 2023, 8:12am UTC](https://community.hubspot.com/t/remove-a-item-from-the-list/78946 "2023-04-08T08:12:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sapna1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sapna1/32/71182_2.png) [@Sapna1](https://community.hubspot.com/u/Sapna1)\
**Post date:** [April 8, 2023, 8:12am UTC](https://community.hubspot.com/t/remove-a-item-from-the-list/78946/1 "2023-04-08T08:12:21Z")

</div>

Hello,

I want to remove a item from the any object list. Can it is possible in cms hubl.

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [April 10, 2023, 8:20am UTC](https://community.hubspot.com/t/remove-a-item-from-the-list/78946/2 "2023-04-10T08:20:40Z")

</div>

Hello @Sapna1  
Let’s say you have a list of items called `my_list`, and you want to remove the item at index `2`. Here’s how you can do it:

```lia-code-sample
{% set my_list = ['apple', 'banana', 'orange', 'grape'] %}

{% set index_to_remove = 2 %}

{% set my_list = my_list[:index_to_remove] + my_list[index_to_remove+1:] %}

{{ my_list }}

```

In this example, we first set the original list `my_list` to `['apple', 'banana', 'orange', 'grape']`. Then, we set the `index_to_remove` variable to `2`, indicating that we want to remove the item at index `2` (which is `'orange'`).

Finally, we reassign the `my_list` variable to a new list that consists of everything before the item we want to remove (`my_list[:index_to_remove]`), concatenated with everything after the item we want to remove (`my_list[index_to_remove+1:]`). This effectively removes the item at index `2` from the list.

You can adapt this code to work with any list of objects that you have in your CMS HubL template. Just replace the `my_list` variable with your own list variable, and set the `index_to_remove` variable to the index of the item you want to remove.  
Thanks & Regards  
Himanshu Rauthan

---

<div class="post-metadata">

**Author:** ![Indra](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/indra/32/98381_2.png) [@Indra](https://community.hubspot.com/u/Indra)\
**Post date:** [April 11, 2023, 7:29am UTC](https://community.hubspot.com/t/remove-a-item-from-the-list/78946/3 "2023-04-11T07:29:10Z")

</div>

@Sapna1,

What kind of list is it?

I have a examples using the [rejactattr filter](https://developers.hubspot.com/docs/cms/hubl/filters#rejectattr):

From a list of content (contents)

```lia-code-sample
{% set removeItem = 'item-slug' %}
{% set newContents = contents|rejectattr("slug", "equalto", removeItem) %}

```
