CoffeeScript Strings-indexOf() - CoffeeScript

Description

This method accepts a sub string and returns the index of its first occurrence within the calling String object. It also accepts an optional parameter fromIndex which will be the starting point of the search. This method returns −1 if the value is not found.

Syntax

Given below is the syntax of indexOf() method of JavaScript. We can use the same method from the CoffeeScript code.

Example

The following example demonstrates the usage of indexOf() method of JavaScript in CoffeeScript code. Save this code in a file with name string_indexof.coffee


On compiling, it gives you the following JavaScript.

Now, open the command prompt again and run the CoffeeScript file as shown below.

On executing, the CoffeeScript file produces the following output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

CoffeeScript Topics