# JS ~~ 取整數


### 用 ~~ 取得整數值

無條件捨去，取得整數值，效能優於 parseInt

```JS
console.log(~~ -2.34); // -2
```

### 用 ~ 判斷陣列的值是否存在

```JS
const arr = [1, 2, 3];
if (~arr.indexOf(3)) {
  console.log("find!"); // find!
}
```

### 參考資料
- <https://segmentfault.com/a/1190000003731938>
- <https://shunnien.github.io/2017/06/26/JavaScript-Double-bitwise-not/>


---

> 作者: [Admin](https://free.is-cool.dev/about)  
> URL: https://free.is-cool.dev/posts/js-bitwise-not/  

