โ07-10-2020 07:18 AM
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โ
]
}
}
โ07-10-2020 08:05 AM
slice will work if I have static length of JSON. Wouldnt it be more work to calculate the length and then remove the first?
โ07-10-2020 01:37 PM
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.
โ07-10-2020 01:49 PM
Thats a clean trick. Thanks for sharing it.