Server Connect Array Remove problem

Not sure if this is a bug or just me, but if someone could try advise please.

Here is the error

Sounds simple enough, like the value i am trying to remove is not in the array, but it really is there, so I am not sure why it says it’s missing.

Hi Paul,
Can you provide an example of the array output and the exact value you’re trying to use in the remove step?

Thanks for helping Teo

Here is what I am trying to do.
I have 2 different APIs, both have a list of price options, such as adult, children, infants, however

API_A could have Over21s, Under21s, infants
and
API_B could have adults, children, infants

I would like to add whatever options are in API_B to API_A, only if they do not already exist, so as an end result API_A should have 2 new options added, adults and children, because infants was already there before.

Here is my output when I disable the remove step in my server action just to check

Here is my server action which created this

I have tried the remove step in 2 different ways, both give the same error as my original post
2023-01-30_14-06-43

There is a limitation when using Objects inside the array. IndexOf, Contains or Remove don’t work fine with objects as value.

Here an example in plain JavaScript with indexOf:

const array1 = [];
const array2 = [];

array1.push(1);
array2.push({n:1});

console.log(array1.indexOf(1)); // returns 0
console.log(array2.indexOf({n:1}); // returns -1

Array1 it looks up the value 1 and finds it at index 0. The second array it looks for the object {n:1} but can’t find it, this is because the objects are not the same. The only way to check in an array if there is an object where n is 1 is by looping through it and check for each object the property n. It is a bit difficult to explain to someone without a lot of programming experience, so hope it makes some sense.

If you only use it as an lookup then store the value as a string or number instead of an object. We can change the behavior for these actions to do a deep compare of objects to match them, but that will have some impact on performance. We wanted to keep the array lightweight and fast.

1 Like

Ok, that kind of makes some sense, i can make a bit of a workaround for this to make it look at the values rather than the entire object, thanks for explaining Patrick.
Hopefully soon we will see more array actions, like add to array if unique etc. and i wont need as many steps, for now, this gets me part of the way there at least.