aspose 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 JavaScript Promises Essentials this week in the JavaScript 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: 1475
    
    1
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: 61596
    
  67

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: 1475
    
    1
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