(~$.inArray('orange', apple))
Can anyone explain what is the above code mean in jquery?
what is ~ and .inArray?
(~$.inArray('orange', apple))
Can anyone explain what is the above code mean in jquery?
what is ~ and .inArray?
It means nothing in jQuery as it is JavaScript.
~
is an operator that does something that you’d normally think wouldn’t have any purpose. It is a unary operator that takes the expression to its right performs this small algorithm on it (where N is the expression to the right of the tilde): -(N+1). See below for some samples.
console.log(~-2); // 1
console.log(~-1); // 0
console.log(~0); // -1
console.log(~1); // -2
console.log(~2); // -3
So, unless you actually have an application that needs to run this algorithm on numbers
Search for a specified value within an array and return its index (or -1 if not found).
so in combination if element not find on (~$.inArray('orange', apple))
it will return zero else index will be converted as above given series.