(JS) map() (2019/10/23)(보충필요!!)
개발노트/Javascript2019. 10. 23. 17:17(JS) map() (2019/10/23)(보충필요!!)

개념 배열 내의 모든 요소 각각에 대해서 map()의 return값을 적용시켜 새로운 함수로 만든다. foreach()처럼 배열의 length만큼 반복시켜 배열 값들에게 return값을 적용. Array.map(callbackFunction(elementValue, index, array) 1. elementValue 배열 내에서 현재 값 2. index 배열 내에서 현재 인덱스 번호 3. array 배열 length만큼 배열을 출력한다. 사용방법 let mapping = [1, 2, 3, 4, 5]; let remap = mapping.map(function(element){ return element * 10; }) console.log(remap); // [10, 20, 30, 40, 50] 출력 ..

(JS) filter() (2019/10/14)(보충필요!)
개발노트/Javascript2019. 10. 14. 18:22(JS) filter() (2019/10/14)(보충필요!)

-개념 배열의 한 바퀴 돌면서 걸러내는 메서드이다. array.filter(callbackFunction(element, index, array){}) 1. element 배열을 순회하면서 배열의 값을 출력한다. 2. index 배열을 순회하면서 인덱스 번호를 출력한다. 3. array 배열의 length만큼 배열 전체 값을 출력한다. -사용방법 1. 짝수 걸러내기 let numberArry = [1,2,3,4,5,6,7,8,9,10]; let filterArry = numberArry.filter(function(element){ return element % 2 === 0; }) console.log(filterArry); // [2, 4, 6, 8, 10] 출력 let filterArry = num..

(JS) forEach() (2019/10/3)
개발노트/Javascript2019. 10. 3. 10:59(JS) forEach() (2019/10/3)

-개념 반복문처럼 배열의 length 만큼 한 바퀴 순회한다. array.forEach(callbackFunction(현재 값, 인덱스 번호, 배열 전체){ }) 1. 현재 값 한 바퀴 돌면서 배열의 값을 하나하나 출력한다. 2. 인덱스 번호 한 바퀴 돌면서 배열의 인덱스 번호 하나하나 출력한다. 3. 배열 전체 배열의 length만큼 배열 전체 값을 출력한다. -사용방법 1. 한 바퀴 돌면서 현재 값 가져오기 et array_foreach = ['foreach1', 'foreach2', 'foreach3']; array_foreach.forEach(function(value){ console.log(value); }) // foreach1 // foreach2 // foreach3 출력 array_fo..

(JS) push() (2019/10/2)
개발노트/Javascript2019. 10. 2. 18:54(JS) push() (2019/10/2)

-개념 배열의 끝에 원하는 값을 추가 시킨다. array.push(추가싶은 값) -사용방법 1. 배열 끝에 값 추가하기 let push_array = [1,2,3]; push_array.push(4); console.log(push_array); // [1, 2, 3, 4] 출력 push_array.push(4) push_array배열 마지막에 숫자 4가 들어간다. push()로 값을 추가하면 항상 배열 마지막에 값이 추가 된다. 또한, 문자도 추가할수있다. 2. 값 추가 후 배열 길이 가져오기 let push_array = [1,2,3,4]; let push_length = push_array.push(5); console.log(push_length); // 5 출력 let push_length = ..

(JS) fill() (2019/9/29)
개발노트/Javascript2019. 9. 29. 17:20(JS) fill() (2019/9/29)

-개념 배열의 값을 원하는 지점부터 원하는 값으로 채워 넣을수있다. (배열의 값을 수정하고 싶을때도 가능하다) array.fill(value,start,end) 1.value 채우고 싶은 값의 자리 2.start 시작 지점의 인덱스 번호 3.end 끝 나는 지점의 인덱스 번호. 끝나는 지점의 이전까지만 값이 적용 된다. -사용방법 1. empty 배열에 값 넣기 let empty_array = Array(5); console.log(empty_array); // [empty × 5] 출력 empty_array.fill(1,0,5); console.log(empty_array); // [1, 1, 1, 1, 1] 출력 let empty_array = Array(5) Array()를 사용하여 빈공간이 5개가..

(JS) split() (2019/9/28)
개발노트/Javascript2019. 9. 28. 13:13(JS) split() (2019/9/28)

-개념 하나의 문자열을 구분자를 이용하여 여러 개의 문자열로 나눈다. string.split(cut, count) 1.cut 원본 문자열을 어떤 기준으로 끊어야 할지 설정한다. 즉, 문자열을 나누는 기준 2.count 끊을 문자열의 개수 -사용방법 1. 문자열 한 개씩 나누기 1 2 3 4 let split_string = 'super Pil'; let split_array = split_string.split(''); console.log(split_array); // ["s", "u", "p", "e", "r", " ", "P", "i", "l"] 출력 let split_arry = split_string.split('') split(나누는 기준) 이기 때문에 '' 할 경우 문자열 하나하나를 나눠서 ..

(JS) join() (2019/9/26)
개발노트/Javascript2019. 9. 26. 21:10(JS) join() (2019/9/26)

-개념 배열의 모든 값들을 연결하여 문자열로 출력한다. array.join() -사용방법 1. join()으로 합치기 1 2 3 let arry_join = ['Americano', 'Latte', 'Espresso', 'smoothie']; console.log(arry_join.join()); // Americano,Latte,Espresso,smoothie 출력 arry_join.join() . join()을 하게 되면 ', ' 문자열을 넣지 않아도 ', '를 넣어서 출력된다. 2. 배열 값 전부 연결해서 합치기 1 2 3 let arry_join = ['Americano', 'Latte', 'Espresso', 'smoothie']; console.log(arry_join.join('')); //..

(JS) splice() (2019/9/26)
개발노트/Javascript2019. 9. 26. 19:09(JS) splice() (2019/9/26)

-개념 기존 배열의 값을 삭제, 추가, 변경 등을 할 수 있다. array.splice(start, deleteCount, add) 1.start 배열의 값을 삭제, 추가, 변경하고 싶은 시작점이다. 인덱스 번호로 선택한다. 2.deleteCount 배열의 값을 삭제하고 싶은 개수. 3.add 배열에 추가하고 싶은 값 -사용방법 1. 기존 배열에 바로 값 추가하기 1 2 3 4 let cafe = ['Americano', 'Latte', 'Espresso', 'smoothie']; cafe.splice(0, 0, 'soldout'); console.log(cafe); //["soldout", "Americano", "Latte", "Espresso", "smoothie"] 출력 cafe.splice(0,..

(JS) indexOf() (2019/9/26)
개발노트/Javascript2019. 9. 26. 09:21(JS) indexOf() (2019/9/26)

-개념 문자열에서 찾고자 하는 문자열이 어디에 있는지 찾을 수 있다. 배열에서 찾고자 하는 배열값이 어디에 있는지 찾을 수 있다. **원하는 값이 있는곳의 인덱스 번호로 출력된다. -사용방법 1.문자열 1 2 3 4 let string_indexof = 'indexof'; console.log(string_indexof.indexOf('i')); //0 출력 string_indexof.indexOf('i') string_indexof변수 안에 i 문자열을 찾는다. i가 맨 앞쪽에 있기 때문에 0(인덱스 번호)을 출력한다. 1 2 3 4 let string_indexof = 'iddexof'; console.log(string_indexof.indexOf('d')); //1 출력 string_indexof..

image