cancel
Showing results for 
Search instead for 
Did you mean: 

Array functions

rajendraj
New Contributor II

Is there a way to delete the first entry in an array if the length of the array is more than 1.

if the JSON looks like this:

{
“content”: {
“type”: “SHOP_ITEMS”,
“uris”: [
“Groceries”,
“Cleaning Products”,
“Household Items”
]
}
}

I want the final output to be

{
“content”: {
“type”: “SHOP_ITEMS”,
“uris”: [
“Cleaning Products”,
“Household Items”
]
}
}

7 REPLIES 7

rajendraj
New Contributor II

slice will work if I have static length of JSON. Wouldnt it be more work to calculate the length and then remove the first?

The doc doesn’t actually say this, but the second parameter to slice (end) is optional. If you omit it, it will return the segment from the begin index to the end of the array. So you can just say slice(1) to omit the first element.

image

rajendraj
New Contributor II

Thats a clean trick. Thanks for sharing it.