How to avoid using negative numbers for indexing in arrays by JavaScript
Editor to share with you how to avoid using negative numbers in the array to do the index, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Avoid using negative numbers as indexes in arrays var numbersArray = [1 numbersArray.indexOf 2 3 4 5]; var from = numbersArray.indexOf ("foo"); / / from is equal to-1numbersArray.splice (from,2); / / will return [5]
Note that the index parameter passed to splice is not negative; when it is negative, the element is deleted from the end of the array.
That's all of the article "how JavaScript avoids indexing negative numbers in arrays". 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!