Pluxbox Logo

Delete from array block

Purpose

Delete an item from a list. The items in the list must have a key as an unique identifier.

Input

  • Array
    The list from which you wish to delete the item. Does not trigger any output. Is forgotten when output has been provided.

  • Value
    The unique identifier, aka key. Can be just either just the value of the identifier or an object containing. If an object is provided, the key must have the same path as the objects in the list. (e.g. node.id). If a list has been given, this will trigger the output.

  • Key Path
    Where to find the unique identifier, aka key, on the objects in the list. Will not trigger any output.

Output

  • Array
    A new list without the delete item.

Example

Here I have a list where I wish to delete 'Item2'. The list looks like this:

	[
	  {
	    "node": {
	      "id": "Item1",
	      "A": "a1",
	      "B": "b1",
	      "C": "c1"
	    }
	  },
	  {
	    "node": {
	      "id": "Item2",
	      "A": "a2",
	      "B": "b2",
	      "C": "c2"
	    }
	  },
	  {
	    "node": {
	      "id": "Item3",
	      "A": "a3",
	      "B": "b3",
	      "C": "c3"
	    }
	  }
	]

I can delete my item in two ways. Here I just provide the value of the identifier:

	graph LR
	A([list]) --array--> D(Delete from array)
	B(["Item2"]) --value--> D
	C(["node.id"]) --Key path--> D
	D --array--> E([New list])

Instead of just providing "Item2" as my value, I can also provide an object, as long as the path to the key matches the objects in the list.

	{
	  "node": {
	    "id": "Item2",
	    "A2": "a",
	    "Other fields": "Does not need to match"
	  }
	}

Caveats

  • Be aware this block only looks for a match on a key, and will delete the element if there's a match. Even if everything else in the object sent to the value field, is completely different.
  • Remember to keep the array input updated, if you wish to be able to delete multiple instances.