일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Front-end
- 스쿠버다이빙
- 뱀파이어서바이벌
- 개발툴
- 공략
- 야생의숨결
- 세부
- ubuntu
- psql
- 씨홀스
- 어드벤스
- window
- hybride
- docker
- 젤다의전설
- 여행
- JavaScript
- poe2
- window10
- WebView
- 오픈워터
- 다이빙
- JS
- 엘든링
- PostgreSQL
- 페오엑
- 취미
- guide
- 게임
- Linux
- Today
- Total
목록JS (7)
Rianshin

API의 response 및 request에서 JSON형태로 사용할때가 자주 있다. 이때, 정렬을 통하여 보다 key값을 찾기 쉽게 정렬을 할수가 있는데, 다음과 같이 하면된다. let beforeObj = { "b": 2, "a": 4, "d": 56, "1": 1 } let afterObj = {}; //Solution 1 Object.keys(beforeObj).sort().forEach(function(key) { afterObj[key] = beforeObj[key]; }); //Solution 2 Object.keys(beforeObj).sort().forEach( key => { afterObj[key] = beforeObj[key]; }); console.log(afterObj) 위의 실행..

getByteLength: function(string) { if (string == null || string.length == 0) { return 0; } let size = 0; for (let idx in string.length) { size += this.charByteSize(string.charAt(idx)); } return size; } charByteSize: function(ch) { if (ch == null || ch.length == 0) { return 0; } let charCode = ch.charCodeAt(0); if (charCode

자주 사용하는 함수중하나인 sort를 이용하여 내림차순, 오름차순 으로 정렬을 하는 방법은 다음과 같이 하면 된다. 날짜를 비교하기위하여 String 을 Date로 형변환을 해야 비교가 가능해진다. var arr = [ {date :""}, {date :"2022-10-14 19:00"}, {date :"2022-10-15 10:00"}, {date : "2022-10-13 10:00"} ]; console.log(arr) let test = arr.sort((a, b) => new Date(a.date) - new Date(b.date)) console.log(test) test = arr.sort((a, b) => new Date(b.date) - new Date(a.date)) 소스 참고 : htt..

HTML 삽입 미리보기할 수 없는 소스 //소문자 => 대문자 var str = "abcd" console.log(str.toUpperCase()) //대문자 => 소문자 var str2 = "ABCD" console.log(str2.toLowerCase())

formatter: function () { var date = new Date(); var dateFormatter = function dateFormatter(date, format) { try { var arr = []; var seperator = []; if (date === undefined || date === null) { return null; } if (typeof date === 'string') { arr = date.split(/\D/), seperator = ['', '', '']; if (arr.length === 1) {// 월일년을 따로 넣는다. arr = [date.substr(0, 4), date.substr(4, 2), date.substr(-2)]; } } else ..
function calcAge(birth) { var date = new Date(); var year = date.getFullYear(); var month = (date.getMonth() + 1); var day = date.getDate(); if (month < 10){ month = '0' + month; } if (day < 10){ day = '0' + day; } var monthDay = month + day; birth = birth.replace('-', '').replace('-', ''); var birthdayy = birth.substr(0, 4); var birthdaymd = birth.substr(4, 4); var age = monthDay < birthdaymd ?..