File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript indexOf Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript indexOf Method" Watch "JavaScript indexOf Method" New topic
Author

JavaScript indexOf Method

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
I am using the following:

if(0 === version.indexOf("5"))

However. if version equals a value like 4.2 I get an error. How can I make the js look at 4.2 as a string and not a numeric value?

I am passing the version as such:

function checkVersion(version){}

I found that using typeof then .toString() works.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Well, yeah. indexOf() is a method of strings, so it doesn't exist on numbers.

What does exist on numbers is a toString() method.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
Bear Bibeault wrote:Well, yeah. indexOf() is a method of strings, so it doesn't exist on numbers.

What does exist on numbers is a toString() method.


Thanks again Bear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaScript indexOf Method
 
Similar Threads
Has anybody.....
OSGi and Equinox: Creating Highly Modular Java Systems Book
which software should I use ?
[JBOSS 4.2] startup failed with Eclipse 3.3 Europa
EJB Lookup problem