Buffer is a temporary memory storage which stores the data when it is being moved from one place to another. It is like the array of integers.
The Buffer.indexOf() method firstly checks for the input value, if it present in the buffer then it returns the first position (index) from where the value is starting.
buffer.indexOf( value, start, encoding )
Parameters: This method accept three parameters as mentioned above and described below:
- value: This parameter holds the value that you want to find in the buffer.
- start: It is an optional parameter. It refers to the starting index from which the elements of input buffer will be searched. The default value is 0.
- encoding: It is an optional parameter. If the needed value is string, then you can add the encoding type. The default value is utf-8.
Return Value: The index from where the searched value is starting. It returns -1 if the value is not present in the buffer.
Below examples illustrate the use of Buffer.indexOf() method in Node.js:
1 0 -1
Note: The above program will compile and run by using the
node index.js command.
- Nodejs | Automatic restart NodeJs server with nodemon
- Nodejs console.timeLog() Method
- Nodejs - Connect MongoDB with Node app using MongooseJS
- Cowsay in Nodejs using Requests library
- Nodejs | Web Crawling using Cheerio
- Web-Socket in NodeJS
- Signup Form Using Nodejs and MongoDB
- Dockerizing a simple Nodejs app
- Nodejs | DNS
- Encrypting Data in NodeJS
- Difference between NodeJS and AngularJS
- Nodejs | Jimp
- Nodejs – Connect Mysql with Node app
- Nodejs | DNS | setServers()
- NodeJS | Building simple REST API in express
- NodeJs - Handling invalid routes
- Nodejs | authentication using Passportjs and passport-local-mongoose
- Nodejs | GM charcoal() Function
- Nodejs | GM blur() Function
- Nodejs | GM sharpen() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.