array

    [드림코딩] 유용한 배열(array) api (2) : filter, map, some, every

    class Coder { constructor(name, age, enrolled, score) { this.name = name; this.age = age; this.enrolled = enrolled; this.score = score; } } const coders = [ new Coder('A', 29, true, 45), new Coder('B', 28, false, 80), new Coder('C', 30, true, 90), new Coder('D', 40, false, 66), new Coder('E', 18, true, 88), ] filter enrolled가 true인 코더만 골라 새로운 배열을 만들어보자. const result = coders.filter((coder) => co..

    [드림코딩] 유용한 배열(array) api (1) : join, split, reverse, slice, find

    join 배열의 모든 데이터를 string으로 합쳐 변환한다. const goodcoders = ['noran', 'paran', 'black', 'white']; const result = goodcoders.join(); console.log(result); //noran,paran,black,white 참고 아래처럼 구분자를 전달하면 전달된 구분자로 구분되어 나타난다. const result = goodcoders.join(|); console.log(result); //noran|paran|black|white split string 데이터를 배열로 만든다. const coders = 'noran,paran,black,white'; const result = coders.split(','); co..

    [mdn, 드림코딩 외] 배열(array) (4) : 검색 (indexOf,lastIndexOf,includes)

    배열을 만들었다. const goodcoders = ['noran', 'paran', 'black', 'white', 'noran']; 검색 indexOf : 데이터의 인덱스 찾기 console.log(goodcoders.indexOf('paran')) //1 아래처럼 배열에 존재하지 않는 데이터의 인덱스를 찾으면 -1로 뜬다. console.log(goodcoders.indexOf('green')) //-1 아래처럼 배열에 중복으로 존재하는 데이터의 인덱스를 찾으면 첫번째 데이터의 인덱스로 뜬다. console.log(goodcoders.indexOf('noran')) //0 lastIndexOf : (중복되는 데이터의 경우) 마지막 데이터의 인덱스 찾기 배열에 중복으로 존재하는 데이터의 인덱스를 찾으..

    [mdn, 드림코딩 외] 배열(array) (2) : 맨뒤/맨앞부터 추가,삭제(push/pop,unshift/shift)

    배열을 만들었다. const goodcoders = ['noran', 'paran']; 추가 push : 맨 뒤에 추가하기 goodcoders.push('black','white'); unshift : 맨 앞에서부터 추가하기 goodcoders.unshift('yellow','orange'); 삭제 pop : 맨 뒤를 삭제하기 goodcoders.pop(); shift : 맨 앞에서부터 삭제하기 goodcoders.shift('yellow','orange'); 우선순위 shift와 unshift는 pop과 push보다 느리다. (데이터의 맨 뒤를 추가하고 삭제하는 것은 쉽지만, 맨 앞을 추가/삭제하는 것은 한칸씩 index가 밀리는 것이기 때문.) 출처 : 드림코딩 https://www.youtube.c..

    [mdn, 드림코딩 외] 배열(array) : 배열에의 접근과 looping

    object와 자료구조의 차이 object는 서로 연관된 특징을 묶어놓는다. 자료구조는 비슷한 타입의 object들을 묶어놓는다. 배열(array) 배열은 0부터 시작하는 칸칸으로 짜여진 index를 가진 자료구조를 말한다. 배열의 선언 const coder1 = new Array(); const coder2 = [1,2]; index position (index에 접근하기) 배열을 만들었다. const goodcoders = ['noran', 'paran']; 이 배열의 정보 console.log(goodcoders); // 2) ['noran', 'paran'] //펼치면 아래 정보가 나온다. //0: "noran" //1: "paran" //length: 2 //[[Prototype]]: Array..