How to use the indexOf () and lastIndexOf () methods in JavaScript
This article mainly shows you "how to use the indexOf () and lastIndexOf () methods in JavaScript". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn how to use the indexOf () and lastIndexOf () methods in JavaScript.
IndexOf () and lastIndexOf ()
IndexOf () searches the array for elements and returns its index. The second parameter specifies where to start the search
LastIndexOf () starts searching for elements at the end of the array and returns its index. The second parameter specifies where to start the search
Var str1 = [console.log (str1.indexOf (2); / / 1console.log (str1.lastIndexOf (2)); / / 1 is all the contents of the article "how to use indexOf () and lastIndexOf () in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!