JQuery: What does this code mean?

This question already has an answer here:

  • How does !!~ (not not tilde/bang bang tilde) alter the result of a 'contains/included' Array method call? 13 answers

  • 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

    Source Taken from

    inArray

    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.

    链接地址: http://www.djcxy.com/p/74966.html

    上一篇: 如何缩短我的条件陈述

    下一篇: JQuery:这个代码是什么意思?