This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Sergey Nikishkin
Posted Oct 07 - Read on Facebook

Hi, guys!

Sorry if such question already was. Is there a way to remove item from array and then put it back?

4 Comments

Jonas Treub

If you want to remove the last element you can use array.pop(). Removing the first element can be done with array.shift(). Removing an item from any position can be achieved with area.splice(startPosition, itemCount). Startposition is the index of the item and itemCount the amount of items you want to grab out of the array.

Jonas Treub

When the item can be inserted as the last item you can use array.push(element). If it needs to be inserted at any different location, you can use the same array.splice() method. This time with an itemCount of 0, but with a third argument which is the item to insert.

Jonas Treub

Here is an example:

array = [1, 1, 2, 4, 5]
print array
# delete one item at index 0
array.splice(0, 1)
print array
# insert number 3 at index 2
array.splice(2, 0, 3)
print array

Sergey Nikishkin

Jonas Treub, thank you for your detailed answer!

Read the entire post on Facebook