[program-l] Re: array.splice is not a function?

  • From: Erik Burggraaf <burggraaferik@xxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Tue, 11 Jan 2022 14:50:34 -0500

I was hoping to modify the original array.  Filter will leave the original
in tact and place the working articles in a new array.  Kind'a sloppy for
this purpose in my view.

Array.slice is for strings which are just essentially an array of
characters.  Slice returns the portion of a string between two elements
such as 0 for the first and indexOf(some letter) for the end point.  Not
quite what we're looking for.

Here's an idea what I've been reading:
https://love2dev.com/blog/javascript-remove-from-array/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
https://www.freecodecamp.org/news/lets-clear-up-the-confusion-around-the-slice-splice-split-methods-in-javascript-8ba3266c29ae/

Best,

Erik

On Tue, Jan 11, 2022 at 2:02 PM Soronel Haetir <soronel.haetir@xxxxxxxxx>
wrote:

My docs say Array has 'slice', not 'splice'.

That being said, I would expect you to have better luck using
Array.filter, takes a callback function and an optional 'this'
parameter and returns an array with all elements for which the
callback return is not false.

On 1/11/22, Erik Burggraaf <burggraaferik@xxxxxxxxx> wrote:
Hi all,  I just tried to remove items from an array of html elements
using
splice() and got this error that array.splice is not a function.  Any
idea
why?  I've read four or five articles but nothing illuminating.

My situation is that I wanted to get elements by tag name so that I
didn't
have to use a custom class.  So I swept the elements into an array and
they
work just fine.  Unfortunately, there were more of the same, in this case
articles in my production environment than there are in my test
environment.  I don't need the extra ones, so thought splice would be an
easy way to pull them out.

I looped through the array, testing a condition.  If they meet the
condition they get pulled out.  Otherwise they stay.

But the splice method is not a function or so I'm told by my error
console.

Any suggestions very much appreciated as always.

Thanks,

Erik



--
Soronel Haetir
soronel.haetir@xxxxxxxxx
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: