Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25107

Re: Cannot manipulate array produced with string.match

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Cannot manipulate array produced with string.match
Date 2014-06-28 01:07 +0000
Organization A noiseless patient Spider
Message-ID <lol4g3$or3$1@dont-email.me> (permalink)
References (1 earlier) <lojfg6$i56$2@dont-email.me> <lokbfi$vac$1@dont-email.me> <lokfoe$q6k$1@dont-email.me> <lokjjc$o0v$1@dont-email.me> <loknef$inh$1@dont-email.me>

Show all headers | View raw


On Fri, 27 Jun 2014 23:24:31 +0200, SteveYoungTbird wrote:

> Got it! arr.match produces a string with a space after the comma.
> Therefore 'jim' in the loop was actually ' jim' and therefore didn't
> match,

Observation: You had all the information you needed to solve this, you 
just needed to figure out how to view that information. :)

If you wanted a really deep dissection of the compares to the console you 
could use something like the following, which prints length, character 
and character code mismatches:

var arr = ["fred","jim","pete"," jim","andrew"," jim ","bert",
           "jim ","henry","jim","mike"];
var i = arr.length, j, k;

console.log( arr.toString() );

while ( i-- ) {
    if (arr[i] === 'jim') {
        arr.splice(i, 1);
    }
    else {
        console.log( "'" + arr[i].toString() + "' !== 'jim'" );
        if ( arr[i].toString().length != "jim".length ) {
            console.log( "'" + arr[i].toString() + "'.length = " + 
                         arr[i].toString().length + 
                         " != 'jim'.length = " + "jim".length );
        }
        k = arr[i].toString().length > "jim".length ? 
            arr[i].toString().length : 
            "jim".length;
        for ( j = 0; j < k; j++ ) {
            if ( arr[i].toString().charAt(j) !== "jim".charAt(j) ) {
                console.log( "arr[i].toString().charAt(j) [" + 
                             arr[i].toString().charAt(j) + 
                             "] !== 'jim'.charAt(j) [" + 
                             "jim".charAt(j) + "]" );
            }
            if ( arr[i].toString().charCodeAt(j) !== 
                 "jim".charCodeAt(j) ) {
                console.log( "arr[i].toString().charCodeAt(j) [" + 
                             arr[i].toString().charCodeAt(j) + 
                             "] !== 'jim'.charCodeAt(j) [" + 
                             "jim".charCodeAt(j) + "]" );
            }
        }
    }
}

console.log( arr.toString() );

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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