var array = [2, 5, 9];
var key = 3;
console.log('\nData : ' + key); // Data : 3
console.log(array.indexOf(key) + ' : ' + ~array.indexOf(key)); // -1 : 0
console.log(array.indexOf(key) + ' : ' + !~array.indexOf(key)); // -1 : true
console.log(array.indexOf(key) + ' : ' + !array.indexOf(key)); // -1 : false
key = 2;
console.log('\nData : ' + key); // Data : 2
console.log(array.indexOf(key) + ' : ' + ~array.indexOf(key)); // 0 : -1
console.log(array.indexOf(key) + ' : ' + !~array.indexOf(key)); // 0 : false
console.log(array.indexOf(key) + ' : ' + !array.indexOf(key)); // 0 : true
key = 9;
console.log('\nData : ' + key); // Data : 9
console.log(array.indexOf(key) + ' : ' + ~array.indexOf(key)); // 2 : -3
console.log(array.indexOf(key) + ' : ' + !~array.indexOf(key)); // 2 : false
console.log(array.indexOf(key) + ' : ' + !array.indexOf(key)); // 2 : false
'JavaScript' 카테고리의 다른 글
ES2015 에 대하여 (0) | 2016.03.03 |
---|---|
Promise 사용법 (0) | 2015.12.21 |
Function 객체의 Methods 소개 (0) | 2015.11.23 |
C#에서 JSON 변환하기 (0) | 2015.11.19 |
비교 연산자(&&,||)를 이용한 변수 할당 (0) | 2015.11.19 |