I have Given this JSON structure:
[{"variant_name":"Size","variant_options":["S","M","L","a"]}]
How would you delete an object from the array by key/value?
Let’s say I wish to delete the element with variant_options = S, how to get this result:
[{"variant_name":"Size","variant_options":["M","L","a"]}]
I tried but did’t get any result
3
Answers
You can try using
map()
withfilter()
like the following way:To delete an item from an array in-place:
Array::indexOf()
Array::splice()