배열2 [JavaScript] Array.from()통해 배열 만들기 Array.from()은 문자열등 이터러블한 객체나 유사 배열 새로운 배열로 만들어주는 메서드이다. - 이터러블(iterable)은 Symbol.iterator가 구현된 객체이다. - 유사 배열(array-like)은 인덱스와 length 프로퍼티가 있어 배열처럼 보이는 객체이다. Array.from(인자 1, 인자 2) - 첫 번째 인자는 배열로 만들 이터러블한 객체이다. - 두 번째 객체는 생성한 배열의 모든 원소에 대해 수행할 맵핑 함수이다. 예시 console.log(Array.from("Eddy")); // ['E', 'd', 'd', 'y'] console.log(Array.from({length: 5}, (v, i) => i); // [0, 1, 2, 3, 4] console.log(Arra.. 2023. 11. 8. [JavaScript] Array - 1개의 변수에 여러 개의 값을 순차적으로 저장할 때 사용한다. - Array() 생성자 함수 : const arr = new Array(1,2,3); - 배열 리터럴 방식 : const arr = [1,2,3]; 주로 사용한다. - array.length : 배열의 길이를 나타낸다. (1) 배열의 추가와 삭제 - 배열은 동적으로 요소를 추가나 삭제할 수 있다. var a = []; a[0] = 1; a[2] = 3; console.log(a); // [ 1, , 3 ] console.log(a.length); // 3 delete a[3]; // 요소 값만 삭제 console.log(a); // [ 1, ] a.splice(1,2); // 요소를 완전히 삭제 console.log(a); // [ .. 2023. 10. 26. 이전 1 다음