Error cannot read property of undefined (reading 'trim') angular
페이지 정보
본문
장비로부터 받는 정보 중에 Location이 있습니다. 값은 대충 2F_Pump_NGM01과 같이 팩토리의 층과 에어리어 그리고, 장비명으로 되어 있습니다. 이 값을 언더바(_)로 Split해서 배열의 값을 trim으로 처리하던 중 문제가 발생 했습니다. 아마도, 잘못된 데이타가 들어오거나 데이타에 undefined 또는 null이겠죠?
const str = undefined;
str.trim();
아래와 같이 배열의 요소가 널인지 문자열로 처리가 가능한지 체크해야 합니다.
const arr = [];
const result = typeof arr?.[0] === 'string' ? arr[0].trim() : '';
console.log(result);
이외에도 각각의 요소가 undefined 인지도 비교해줘야 합니다.
추천0 비추천0
- 이전글adb server version (36) doesn't match this client (41); killing... 22.03.23
- 다음글WARNING: Ignoring invalid distribution -ip (c:\python310\lib\site-packages) 22.03.13
댓글목록
등록된 댓글이 없습니다.