Remove item from JSON array based on value

Hello!

I am looking for a solution to remove 1 item from a JSON array based on the value of the item and not the position in the array.

I am creating a photo sharing app.

say 100 users ‘like’ a photo. I will add their userID into an array of ‘likes’.

then say the first user to like the photo decides they dont like it anymore. so they want to remove themself from the list. If nobody else is interacting with that list, the index would be no problem to figure out.

I am wondering if more than 1 person was interacting with a JSON array at the same time which could cause changing indices for any given value in that array, is there a way to delete an array value based on the value itself vs the index of the value in the array.

the idea would be like

var x = [‘car’, ‘poop’, ‘house’]

in X, find any value that = “poop” and delete it

vs in X delete # 1

Hi @jared_gibb,

Do you have a separate table that contains information about the photos? If you do, then information about users who likes a photo would be better represented as a relation to the corresponding user object.

At the present moment updating arrays (such as adding new items or deleting existing array items) requires storing the entire updated array, which may not be the best approach with what you’re trying to do.

Regards,
Mark

1 Like