Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #25097
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Cannot manipulate array produced with string.match |
| Date | 2014-06-27 10:02 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <lojfg6$i56$2@dont-email.me> (permalink) |
| References | <loj5qn$cof$1@dont-email.me> |
On Fri, 27 Jun 2014 09:17:43 +0200, SteveYoungTbird wrote:
> I have produced an array using:
>
> var arr = [];
> arr = string.match(/(?:^| )([a-zäöüß]+)(?= [A-Z])/g);
>
> This works as expected and the array is full and can be seen using
> console.log or alert().
>
> The array consists of words which I need to filter, so I am trying to
> use .splice to remove unwanted instances of the same word using:
>
> for (var i = arr.length - 1; i >= 0; i--) {
> if (arr[i] === 'jim') {
> arr.splice(i, 1);
> }
> }
>
> The for loop doesn't recognize any instances of, for instance, 'jim' in
> the array although there are several.
>
> I tried the loop using an array I made myself and it worked fine, ie:
>
> arr = ['jim', 'bob', 'arthur', 'jim', 'fred']
>
> What is it about the array produced by the string.match that I am not
> understanding? Any help would be much appreciated.
Try using the following:
var i = arr.length;
while ( i-- )
if (arr[i] === 'jim')
arr.splice(i, 1);
else
console.log( "'" + arr[i].toString() + "' !== 'jim'" );
See what console.log is showing for words that don't match jim which you
expected to match jim.
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 09:17 +0200
Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-27 10:02 +0000
Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 20:00 +0200
Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-27 19:13 +0000
Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 22:18 +0200
Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-27 23:24 +0200
Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-28 01:07 +0000
Re: Cannot manipulate array produced with string.match Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-28 01:16 +0000
Re: Cannot manipulate array produced with string.match Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-28 23:53 +0200
Re: Cannot manipulate array produced with string.match SteveYoungTbird <stephen.young@chello.at> - 2014-06-29 22:24 +0200
Re: Cannot manipulate array produced with string.match Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-29 23:19 +0200
Re: Cannot manipulate array produced with string.match JJ <jj4public@vfemail.net> - 2014-06-27 19:31 +0700
csiph-web