String Indexes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Howard Kaikow

    String Indexes

    I was perusing the book Pure Javascript by Wyke, Gilliam, and Ting and came
    upon references to String Indexes on pages 32-33 in the discussion of
    arrays.

    I then looked for more info in the 3rd edition of David Flanagan's
    Javascript The Definitive Guide. I found no mention of String Indexes.
    Is this book out of date?

    Do I need to get a newer edition?
    Which books?

    --
    http://www.standards.com/; See Howard Kaikow's web site.


  • RobG

    #2
    Re: String Indexes

    Howard Kaikow wrote:
    [color=blue]
    > I was perusing the book Pure Javascript by Wyke, Gilliam, and Ting and came
    > upon references to String Indexes on pages 32-33 in the discussion of
    > arrays.
    >
    > I then looked for more info in the 3rd edition of David Flanagan's
    > Javascript The Definitive Guide. I found no mention of String Indexes.
    > Is this book out of date?
    >
    > Do I need to get a newer edition?
    > Which books?
    >[/color]

    I'm guessing you are looking for indexOf and lastIndexOf.

    A Google search for "javascript string index" turned up the
    following useful reference:



    The FAQ provides some help with regular expressions in general:



    No doubt there are hundreds more resources online -
    searching for regular expression links should further
    complete the picture.

    Rob.

    Comment

    • Howard Kaikow

      #3
      Re: String Indexes

      > I'm guessing you are looking for indexOf and lastIndexOf.

      Nope, string index for arrays is not stringmanipulat ion. For example:

      var Stuff= new Array();
      Stuff["Yankees"]=10;
      Stuff["Red Sox"]=7;
      Stuff["Bagels"]=13;
      Stuff["Pizza"]=3;
      document.write( "<BR>Yankee s= " + Stuff['Yankees']);
      document.write( "<BR>Red Sox= " + Stuff['Red Sox']);
      document.write( "<BR>Bagels = " + Stuff['Bagels']);
      document.write( "<BR>Pizza= " + Stuff['Pizza']);


      Comment

      • Steve van Dongen

        #4
        Re: String Indexes

        "Howard Kaikow" <kaikow@standar ds.com> wrote:
        [color=blue][color=green][color=darkred]
        >>> I then looked for more info in the 3rd edition of David Flanagan's
        >>> Javascript The Definitive Guide. I found no mention of String Indexes.
        >>> Is this book out of date?[/color][/color][/color]

        Highly doubtful. I've never heard the term 'string indexes' before.
        Look for information on objects and properties. In MS JScript, they
        are also known as "expando" properties.
        [color=blue][color=green]
        >> I'm guessing you are looking for indexOf and lastIndexOf.[/color]
        >
        >Nope, string index for arrays is not stringmanipulat ion. For example:
        >
        >var Stuff= new Array();
        >Stuff["Yankees"]=10;
        >Stuff["Red Sox"]=7;
        >Stuff["Bagels"]=13;
        >Stuff["Pizza"]=3;
        >document.write ("<BR>Yankee s= " + Stuff['Yankees']);
        >document.write ("<BR>Red Sox= " + Stuff['Red Sox']);
        >document.write ("<BR>Bagels = " + Stuff['Bagels']);
        >document.write ("<BR>Pizza= " + Stuff['Pizza']);[/color]

        If you got that from the book you mentioned before, I'd mildly suggest
        throwing that book away before you learn too much from it. What is
        misleading about this code is that you've created an array named Stuff
        but it doesn't have any items in it. Try adding a
        document.write( Stuff.length) on the end and see how many items are in
        the array.

        The reason you won't find information on 'string indexes' in
        references about Arrays is because the concept has nothing to do with
        arrays. They are really properties on an object. You can add any
        properties you want to a native Javascript object. An Array is simply
        a special type of Object -- which is why the above works -- but if an
        object is what you want then an object is what you should use, e.g.:

        var Stuff= new Object();
        Stuff["Yankees"]=10;
        Stuff["Red Sox"]=7;
        Stuff.Bagels=13 ;
        Stuff.Pizza=3;

        Note the different syntax for accessing the property on the last 2
        lines. Either style can be used to access a property except if the
        property name contains an invalid character (like the space in Red
        Sox) in which case you must use the object[property] form.

        Regards,
        Steve

        Comment

        • Howard Kaikow

          #5
          Re: String Indexes

          "Steve van Dongen" <stevevd@hotmai l.com> wrote in message
          news:nhmpm01004 cfq1cs7k215na4r c4hih5q0p@4ax.c om...[color=blue]
          > "Howard Kaikow" <kaikow@standar ds.com> wrote:
          > Highly doubtful. I've never heard the term 'string indexes' before.
          > Look for information on objects and properties. In MS JScript, they
          > are also known as "expando" properties.[/color]

          I too had guessed that they were really objects.
          [color=blue]
          > If you got that from the book you mentioned before, I'd mildly suggest
          > throwing that book away before you learn too much from it.[/color]

          I would concur.

          Several years ago, I purchased the Pure Javascript book and te 3rd edition
          of David Fanagan's book.
          My recollection is that I thout that DF's book was well done and that the
          Pure Javascript book was not at all well done.
          [color=blue]
          > What is
          > misleading about this code is that you've created an array named Stuff
          > but it doesn't have any items in it. Try adding a
          > document.write( Stuff.length) on the end and see how many items are in
          > the array.[/color]

          Ayup, I did that yesterday and got the expected result of 0.
          [color=blue]
          > The reason you won't find information on 'string indexes' in
          > references about Arrays is because the concept has nothing to do with
          > arrays. They are really properties on an object.[/color]

          That's what it looked like to me.
          [color=blue]
          > You can add any
          > properties you want to a native Javascript object. An Array is simply
          > a special type of Object -- which is why the above works -- but if an
          > object is what you want then an object is what you should use, e.g.:
          >
          > var Stuff= new Object();
          > Stuff["Yankees"]=10;
          > Stuff["Red Sox"]=7;
          > Stuff.Bagels=13 ;
          > Stuff.Pizza=3;
          >
          > Note the different syntax for accessing the property on the last 2
          > lines. Either style can be used to access a property except if the
          > property name contains an invalid character (like the space in Red
          > Sox) in which case you must use the object[property] form.[/color]

          Thanx.


          Comment

          • Howard Kaikow

            #6
            Re: String Indexes

            "Steve van Dongen" <stevevd@hotmai l.com> wrote in message
            news:nhmpm01004 cfq1cs7k215na4r c4hih5q0p@4ax.c om...[color=blue]
            > "Howard Kaikow" <kaikow@standar ds.com> wrote:
            >[color=green][color=darkred]
            > >>> I then looked for more info in the 3rd edition of David Flanagan's
            > >>> Javascript The Definitive Guide. I found no mention of String Indexes.
            > >>> Is this book out of date?[/color][/color]
            >
            > Highly doubtful. I've never heard the term 'string indexes' before.
            > Look for information on objects and properties. In MS JScript, they
            > are also known as "expando" properties.[/color]

            I see that "expando" is referred to in the 4th edition of David Flanagan's
            book, but not in the 3rd edition.

            Since I already have the 3rd edition, do I need the 4th edition.

            Wonder where MSFT came up with the term "expando"?
            Sounds like the name of a villain in a Superman or Batman story.


            Comment

            Working...