JS tweak to remove an array item

(figured I’d ask you because of your famed JS one-liner prowess)

If you visit here,
and examine source, you’ll see I’m using parseJSON script to make my array of filenames usable by Lightbox.

Trouble is that on this screen, I’ve hardcoded “image1” for the main image.
And underneath is a repeat area to show up to 4 more images (images 2-5),
But the repeat starts at 1 (which has already been shown) so it appears twice.
If you activate the Lightbox, you’ll see the main image twice.

Easiest way I thought to fix this was to make another parse function which would eliminate the 1st element, returning only image#2+ and thus I wouldn’t have a dup of #1

What JS would be needed at the end of “return JSON.parse(str)” to strip the 1st item?

Hi Robert,

If str is actually a stringified array you would just need to slice(1).

return (JSON.parse(str)).slice(1)

1 Like