본문 바로가기

javascript69

Date getMonth 달 2자리로 출력하기 2020/7/7 -> 2020/07/07 const month = date.getMonth() + 1; return month < 10 ? `0${String(month)}` : `${String(month)}`; const day = date.getDate(); return day < 10 ? `0${String(day)}` : `${String(day)}`; stackoverflow.com/questions/6040515/how-do-i-get-month-and-date-of-javascript-in-2-digit-format How do I get Month and Date of JavaScript in 2 digit format? When we call getMonth() and getDate().. 2020. 9. 28.
소수점 제거, 반올림 // 소수점 올림, 정수 반환 Math.ceil() // 소수점 버림, 정수 반환 Math.floor() // 소수점 반올림, 정수 반환 Math.round() wdevp.tistory.com/59 javascript 소수점 버림, 올림, 반올림 # 자바스크립트 숫자 타입의 값 버림, 올림 등 다양한 방법 다른 언어들 처럼 숫자를 쉽게 변환할 수 있는 편리한 함수가 자바스크립트에서 존재하며 이때는 Math 객체를 사용합니다. 아래는 Math wdevp.tistory.com 2020. 9. 23.
[Date] getTime, 날짜 빼기, 날짜 계산 getTime () 동일한 시간 값으로 날짜 객체를 생성합니다. var today = new Date(); var copy = today.getTime(); console.log(copy); //1602754747026 날짜 빼기, 날짜 계산 const today = new Date().getTime(); const endDt = new Date(endDtTimestamp); const remainingTime = Math.ceil((endDtTimestamp - today) / (24 * 60 * 60 * 1000)); // Number of milliseconds per day // Math.ceil() : 소수점 올림, 정수 반환 console.log(remainingTime, endDt); con.. 2020. 9. 23.
browser language 현재 브라우저 언어 감지 navigator.language webisfree.com/2015-11-10/%ED%98%84%EC%9E%AC-%EB%B8%8C%EB%9D%BC%EC%9A%B0%EC%A0%80%EC%97%90-%EC%84%A4%EC%A0%95%EB%90%9C-%EC%96%B8%EC%96%B4%EA%B0%92-%ED%99%95%EC%9D%B8-%EB%B0%A9%EB%B2%95 현재 브라우저에 설정된 언어값 확인 방법 자바스크립트를 사용하여 다양한 언어를 지원하기 위해서 고려할 부분이 많습니다. 특히 방문자, 클라이언트의 언어가 무엇인지 알아야할 필요가 있는데 이를 확인하는 방법이 문엇이 있을까�� webisfree.com 2020. 9. 23.
async-await를 이해하기 위한 노력 async-await가 가장 최신의 비동기 문법이고, callback, promise보다 가독성이 좋다는 것은 알고 있다. 하지만 async-await를 언제, 왜 써야 하는지 잘 이해가 되지 않았다. 비동기가 뭔지부터 알자. function getData() { var tableData; $.get('https://domain.com/products/1', function(response) { tableData = response; }); return tableData; } console.log(getData()); 대표적인 비동기 사례로 jQuery의 $.get이 있다. 위 코드를 실행하면 콘솔에는 undefined가 찍힌다. 왜냐하면 $.get에서 데이터를 받아올 때까지 기다리지 않고 tableDa.. 2020. 9. 23.
배열 type 명시하기 const [config, setConfig] = useState({ id: 1 width: '100px', items: array, }); 2020. 9. 22.
배열의 객체에서 특정 값이 있는 index 찾기 var arr3 = [ { num : 0, name : "홍길동" }, { num : 1, name : "박보검" }, { num : 2, name : "강호동" } ]; var index = arr3.findIndex(i => i.name == "강호동"); console.log(index); // 2 yeolco.tistory.com/157 2020. 9. 21.
[error] Property does not exist on type 'never' Error useState hook을 사용하여 배열을 정의할 때 타입스크립트 에러가 발생함. 해결 useState 뒤에 를 명시해준다. const [arr, setArr] = useState([]) 2020. 9. 21.
includes : 배열 속 요소, 문자열 속 문자 유무(boolean) https://www.codingfactory.net/10899 JavaScript / Object / String.includes() / 특정 문자열을 포함하는지 확인하는 메서드 .includes() .includes()는 문자열이 특정 문자열을 포함하는지 확인하는 메서드입니다. IE는 Edge부터 지원합니다. 문법 string.includes( searchString, length ) searchString : 검색할 문자열로 필수 요소입니다. 대� www.codingfactory.net ['en', 'fr', 'es', 'pt'].includes(language) 2020. 9. 18.