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.