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.