String Indexes

H

Howard Kaikow

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?
 
R

RobG

Howard said:
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?

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

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

http://www.quirksmode.org/js/strings.html

The FAQ provides some help with regular expressions in general:

http://www.jibbering.com/faq/

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

Rob.
 
H

Howard Kaikow

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

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

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

Steve van Dongen

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.
I'm guessing you are looking for indexOf and lastIndexOf.

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

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

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
 
H

Howard Kaikow

Steve van Dongen said:
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.

I too had guessed that they were really objects.
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.

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.
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.

Ayup, I did that yesterday and got the expected result of 0.
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.

That's what it looked like to me.
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.

Thanx.
 
H

Howard Kaikow

Steve van Dongen said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top