![]() Most of the time, this is likely not what you intended. Because the strict comparison NaN = NaN returns false, the indexOf method will return -1 when searching for NaN in an array: assert(. However, there's one edge case in which indexOf and includes behave differently, and that is NaN. There's no more fiddling around with indices just to determine array membership. Notice how the if-condition almost reads like a regular English sentence. The () method makes this check easier to read and more semantically meaningful to human readers: const numbers = Up until now, you've probably compared the return value of the () method against -1 to check whether an array contains a certain value: const numbers = The other new feature is the exponentiation operator **, which provides a little syntactic sugar for Math.pow. ![]() () determines whether an array contains a given element and returns either true or false. ![]() The () method defined on the Array prototype is one of the two new features that ECMAScript 2016 standardizes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |