switch (situation) {
case si1:
value1;
break;
case si2:
value2;
break;
...
default:
etc;
}
situation값이 si1이면 value1, si2이면 value2 ... 어느 것도 아니면 etc
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
jquery가 javascript보다 먼저 실행됨
$(document).ready(function(){
// process..
});
$("p") : element 셀렉터
$('ui.first') : ui클래스에 있는 이름이 first 셀렉터
$("#id") : id 셀렉터
$(".class") : class 셀렉터
.val() : input 박스 값 가져오기
.val('바꿀 값') : input 박스 값 바꾸기
.show() : div 보이기
.hide() : div 숨기기
.remove() : 값 지우기
.text('바꿀값') : 버튼값 바꾸기
.append() : id 태그에 이어 붙이기
.wrap() : 내가 지정한 효과로 감싸기
.class() : class 따로 지정해주기
.replace() : 내용 바꾸기
.keydown() / .keypress() / .keyup() : 키입력시 / 키입력시(Enter, Tab키에는 발생하지 않음) / 키 입력 후 발생
.load() : HTML 로드시키기
AJAX는 리로드 하지않고 JSON,XML형태로 필요한 데이터만 불러와 갱신
장점
- 속도향상
단점
- 보안상 문제
- 연속 요청시 과부화
- 히스토리 관리 불가
- 디버깅 용이하지 않음
$.ajax({
url: "/rest/1/pages/245", // 클라이언트가 HTTP 요청을 보낼 서버의 URL 주소
data: { name: "홍길동" }, // HTTP 요청과 함께 서버로 보낼 데이터
method: "GET", // HTTP 요청 메소드(GET, POST 등)
dataType: "json" // 서버에서 보내줄 데이터의 타입
})
// HTTP 요청이 성공하면 요청한 데이터가 done() 메소드로 전달됨.
.done(function(json) { })
// HTTP 요청이 실패하면 오류와 상태에 관한 정보가 fail() 메소드로 전달됨.
.fail(function(xhr, status, errorThrown) { })
// 요청완료
.always(function(xhr, status) { });
성공시와 실패시를 나누어 진행
$.ajax({
type: "GET", // "POST"
url: url,
data: data,
success: success,
dataType: dataType
});
GET 또는 POST 방식으로 값 받음
for(자료형 변수 : 객체) { }
++ javascript는 for(let 변수 in 객체) { }
let animals = [
{ species: 'mammalia', name: "cat" },
{ species: 'reptiles', name: "lizard" },
{ species: 'amphibia', name: "flog" },
{ species: 'mammalia', name: "dog" },
{ species: 'amphibia', name: "salamander" }
];
let result = animals.filter((value) => value.species == 'mammalia')
console.log(result);
// output :
//[
//{ species: "mammalia", name: "cat" },
//{ species: "mammalia", name: "dog" }
//]
const arr = [ 10, 20, 30, 40, 50 ];
//일반 함수 형태
arr.map(function(item, index) {
console.log(index+"번 값", item);
});
//화살표 함수 형태
arr.map((item, index) => {
console.log(index+"번 값", item);
});
// output :
//0번 값 10
//1번 값 20
//2번 값 30
//3번 값 40
//4번 값 50
array : recude를 적용할 배열
callback : 배열의 각 요소에 대해 실행할 콜백 함수. 콜백 함수는 다음 매개변수를 가진다.
accumulator : 콜백 함수의 반환 값 또는 이전 순회에서의 최종 결과값. 초기 값(initialValue)이 제공된 경우 첫 번째 순회에서는 initialValue로 설정된다.
currentValue : 현재 순회 중인 배열의 요소
currentIndex (옵션) : 현재 순회 중인 배열의 요소 인덱트
array (옵션) : reduce 함수가 호출된 배열
initialValue (옵션) : 콜백 함수의 첫 번째 순회에서 accumulator로 사용될 초기 값. 초기 값이 제공되지 않으면 배열의 첫 번째 요소가 초기 값이 된다
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
console.log(sum); // 출력 결과: 15
ArrayList <Object> list = new ArrayList <>();
List <Object> list = new ArrayList <>(); // 이게 좀 더 효과적(유연)
메모리에 한번 할당되어 프로그램이 종료될 때 해제
Static 영역에 할당된 메모리는 모든 객체가 공유하는 메모리