강좌
2-22 / 2-23 / 2-24 / 2-25 / 2-26
const target = ['가','나','다','라','마']
;
target.pop();
target.shift();
target.splice(1,2);
const target = ['가','라','마']
;target.splice(1);
const target = ['가']
;target.splice(1,3,'타','파');
const target = ['가','타','파','마']
;['가', '카', '나', '다', '라', '마']
const result1 = target.includes('다');
console.log(result1);
const result1 = arr.indexOf('다');
const result1 = arr.lastIndexOf('라');
const result1 = arr.indexOf('카');
const arr=['가','나','다','라','마'];
let i=0;
while(i<arr.length){
console.log(arr[i]);
i++;
}
const arr='가나다라마';
let i=0;
while(i<arr.length){
console.log(arr[i]);
i++;
}
const arr=['가','라','다','라','마','라'];
let i = 0;
while(i<5){
const result1= arr.indexOf('라');
if(result1===-1){
break;
}
arr.splice(result1,1)
i++;
}
console.log(i);
const arr=['가','라','다','라','마','라'];
while(arr.indexOf('라')>0){
arr.splice(arr.indexOf('라'),1)
}
// 1번코드
const arr=['가','라','다','라','마','라'];
let index = arr.indexOf('라');
while(index>-1){
arr.splice(index,1);
index = arr.indexOf('라');
}
// 2번코드
const arr=['가','라','다','라','마','라'];
let index = arr.indexOf('라');
while(index>-1){
arr.splice(index,1);
}
index = arr.indexOf('라');
코드 한 줄의 유무차이이다.index = arr.indexOf('라');
을 안넣어주면, 반복문 밖에서 index에 넣은 1이 계속 유지되어서 배열의 첫번째 요소만 지우는 상황이 나온다.
- function함수
function a() { console.log("hello"); } a(); //함수 사용하기
function b() {
return '반환값';
console.log("hello");
}
return undefined
가 생략되어있다.function c() {
if(조건문){
return;
}
console.log("hello");
}
function d() {
return [1,2];
}
return 1,2;
개념
function e(parameter) { console.log(parameter); }
e('hello');
- parameter -> 매개변수
- 변수 선언문 하지마라 -> 오류 뜬다.
- (int x, y) 이렇게 하지마
- 'hello' -> 인수
- 함수를 사용할 때, 인수가 매개변수에 저장되고, 함수가 실행된다.
- 매개변수는 여래 개 둘 수 있다.
function f(x,y,z,w) { console.log(x,y,z,w); console.log(arguments); }
f('치킨','피자','햄버거');
- 매개변수 w에는 값을 넣지 않았음 -> 기본값인 undefined 출력된다.
f('치킨','피자','햄버거','돈까스','스시');
- '스시'는 매개변수에 대입이 불가능하므로, 무시된다.
arguments
화살표 함수에서는 못쓰는 기능이다. function함수에서만 쓸 수 있다.
console.log(arguments);
-> 인수들을 배열형태로 보여준다.
- 화살표 함수
const f = (x, y, z) => { return x * y * z } f(2,3,4); //함수 사용하기
- 중괄호와 return이 바로 이어질 경우, 둘다 생략 가능
const f = (x, y, z) => x * y * z f(2,3,4); //함수 사용하기
const zeroCho = {
year: 1995,
month: 8,
date: 12,
gender: 'M',
};
:
,
zeroCho.이름 = 값;
zeroCho.job='개발자';
delete zeroCho.gender
function g() {}
g.a='hello';
const arr = [];
arr.b='happy';
console.log(g.a);
console.log(arr.b);
const debug = {
log: function(value){
console.log(value);
},
}
debug.log("happy");