Tutorials References Exercises Menu
Paid Courses

Node.js buffer lastIndexOf() Method

❮ Buffer Module


Return the last occurrence of the letter "e":

var buf = Buffer.from('Hello, and welcome to Rome!');

Run example »

Definition and Usage

The lastIndexOf() method checks if a specified value is present in the buffer and returns the position.

If the specified value occurs more than once, only the position of the last occurrence will be returned.

This method returns -1 if the value to search for never occurs.

See also: the indexOf() method, which returns the first occurrence of the specified value.


buffer.lastIndexOf(value, start, encoding);

Parameter Values

Parameter Description
value Required. What to search for. Legal value types:
Number (Integer)
start Optional. Where to begin the search. Default 0
encoding Optional. If the value is a string, this parameter is used to specify its encoding. Default "utf8"

Technical Details

Return Value: A Number, representing the position where the specified search value occurs for the last time, or -1 if it never occurs
Node.js Version: 6.0.0

❮ Buffer Module