반응형
Array.includes()
array 내 값이 존재하는지 확인
in operator
객체 내 key가 존재하는지 확인
(array의 경우, 해당 index가 존재하는지 확인)
예제
var arr = [5];
console.log('Is 5 is an item in the array: ', arr.includes(5)); // true
console.log('do we have the key 5: ', 5 in arr); // false
console.log('we have the key 0: ', 0 in arr); // true
참고 자료
반응형
'Front-End: Web > JavaScript' 카테고리의 다른 글
[JavaScript] eval() 함수를 사용하지 마세요! eval() is evil! (0) | 2022.11.27 |
---|---|
[js] lastIndexOf (+ 활용법 with indexOf) (0) | 2022.11.17 |
[js] Math.floor vs trunc vs parseInt (0) | 2022.11.16 |
[코딩애플] js part 3-13. Optional Chanining(?.) / Nullish Coalescing (??) (0) | 2022.10.22 |
[코딩애플] js part 3-12. class로 만들어보는 2D 게임 (0) | 2022.10.22 |