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

Front-End 개발시에 console.log를 많이 사용하게 되는데, 특정 console.log같은건 가독성을 주기위에 색깔을 입히기도 한다. 위의 문법과 같이 사용하면 되지만 조금더 눈에 확들어오게 하는 콘솔로그는 다음과 같다. var css = "text-shadow: -1px -1px hsl(0,100%,50%), 1px 1px hsl(5.4, 100%, 50%), 3px 2px hsl(10.8, 100%, 50%), 5px 3px hsl(16.2, 100%, 50%), 7px 4px hsl(21.6, 100%, 50%), 9px 5px hsl(27, 100%, 50%), 11px 6px hsl(32.4, 100%, 50%), 13px 7px hsl(37.8, 100%, 50%), 14px 8p..

#console.assert(expression, object) Log level: Error Writes an error to the console when expression evaluates to false. const x = 5; const y = 3; const reason = 'x is expected to be less than y'; console.assert(x < y, {x, y, reason}); #console.clear() Clears the console. console.clear(); If Preserve Log is enabled, console.clear() is disabled. Alternatively, you can Clear the Console by clicking..

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

Map map은 해당 Array의 데이터를 변환하는데 사용된다. /** 단순 배열일때 값변환 */ const array1 = [1, 4, 9, 16]; // pass a function to map const map1 = array1.map(x => x * 2); console.log(map1); // expected output: Array [2, 8, 18, 32] 결과화면 > Array [2, 8, 18, 32] /** JSON Array 일때 특정 value변환 */ const array1 = [ { name: 'aaa', age: 11 }, { name: 'bbb', age: 22 }, { name: 'ccc', age: 33 }, { name: 'ddd', age: 44 } ]; // pass..