일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- string
- date
- Visual Studio Code
- json
- CMD
- 배열
- Java
- ArrayList
- Files
- js
- 이탈리아
- 인텔리제이
- javascript
- input
- Maven
- 자바
- 테이블
- 자바스크립트
- Eclipse
- 이클립스
- table
- Button
- 문자열
- CSS
- html
- list
- vscode
- Array
- IntelliJ
- windows
- Today
- Total
목록hasOwnProperty (2)
어제 오늘 내일
Object에 특정 이름의 key가 존재하는지 확인하기 위한 방법입니다. in 연산자 hasOwnProperty() 1. in 연산자 객체에 특정 키가 존재하는지 체크하기 위해서, in 연산자를 사용할 수 있습니다. 객체에 특정키가 존재하면 true를 리턴하고, 존재하지 않으면 false를 리턴합니다. const obj = { name: 'anna', age: 20 }; document.write('name' in obj); // true document.write(' '); document.write('address' in obj); // false 2. hasOwnProperty() hasOwnProperty() 메소드를 이용할 수도 있습니다. 마찬가지로, 객체에 특정키가 존재하면 true를 리턴하고..
Javascript의 객체에 특정 속성이 존재하는지 체크하는 방법 3가지를 소개합니다. 1. hasOwnProperty() 함수 const person = { name : 'alice', country: 'korea' } const haveName = person.hasOwnProperty('name'); const haveAge = person.hasOwnProperty('age'); document.writeln(haveName); document.writeln(haveAge); hasOwnProperty 함수는 파라미터로 전달된 property(속성)가 객체에 존재하면 true를 리턴하고, 그렇지 않으면 false를 리턴합니다. 2. in 연산자 사용하기 const person = { name : ..