Array .includes()
determines if an array includes an specified element, returning true
if it includes, false
otherwise.
includes :: (searchElement, ?fromIndex) -> Boolean
searchElement
- the element to search on the array.fromIndex
- the index from which the search starts.
includes :: (searchElement) -> Boolean
[].includes() // false
[].includes(undefined) // false
['foo',3,{}].includes({}) // false
['foo','bar'].includes('zed') // false
[-0].includes(+0) // true
[1,2,3].includes(2) // true
['foo','bar'].includes('foo') // true
[undefined].includes(undefined) // true
includes :: (searchElement, fromIndex >= 0) -> Boolean
['foo','bar','zed'].includes('foo') // true - fromIndex 0 by default
['foo','bar','zed'].includes('foo',1) // false
['foo','bar','zed'].includes('bar',1) // true
// If the fromIndex is greater or equal to the array size,
// the array is not searched and false is returned.
['foo','bar','zed'].includes('bar',10) // false
includes :: (searchElement, fromIndex < 0) -> Boolean
// When fromIndex is negative a computed index is calculated to be used.
// If the computed index if less than 0, the entire array is search.
// The computation goes like this:
// Computed index = Array length + fromIndex
// e.g.
var array = ['a','b','c','d'] // length = 4
array.includes('b', -3) // computed index = 4 + (-3) = 1, result = true
array.includes('b', -1) // computed index = 4 + (-1) = 3, result = false
array.includes('b', -10) // computed index = 4 + (-10) = -6, result = false
Array.prototype.includes (Domenic Denicola, Rick Waldron)
Exponentiation operator returns the result of raising the first operand to the power of the second (e.g. x ** y
).
It will return the same result as Math.pow(x,y)
.
x ** y
// x ** y (aka Math.pow(x,y))
2 ** 2 // 4
2 ** 'a' // NaN
var e = 2
e **= 2 // 4
Exponentiation Operator (Rick Waldron)
- 2ality.com by Axel Rauschmayer
- MDN documentation