TypeScript 배열 조작
8543 단어 TypeScript
1. 배열 의 성명
let array1:Array;
let array2:number[];
2. 배열 초기 화
let array1:Array = new Array();
let array2:number[] = [1,2,3];
3. 배열 요소 할당, 추가, 변경
let array:Array = [1,2,3,4];
console.log(array) // [1, 2, 3, 4]
array[0] = 20; //
console.log(array) // [20, 2, 3, 4]
array[4] = 5; //
console.log(array) // [20, 2, 3, 4, 5]
array.push(6); //
console.log(array) // [20, 2, 3, 4, 5, 6]
array.unshift(8, 0); //
console.log(array); // [8, 0, 20, 2, 3, 4, 5, 6]
삭제
let array:Array = [1,2,3,4];
console.log(array) // [1, 2, 3, 4]
let popValue = array.pop(); //
console.log(array) // [1, 2, 3]
array.splice(0, 1); // (index, deleteCount)
console.log(array) // [2, 3]
array.shift(); //
console.log(array); // [3]
5. 합병, 차단 배열
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(...items: T[][]): T[];
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(...items: (T | T[])[]): T[];
/**
*
*/
slice(start?: number, end?: number): T[];
let array: Array = [1, 2, 3];
let array2: Array = [4, 5, 6];
let arrayValue = 7;
array = array.concat( array2);
console.log(array) // [1, 2, 3, 4, 5, 6]
array = array.concat(arrayValue);
console.log(array) // [1, 2, 3, 4, 5, 6, 7]
let newArray = array.slice(2, 4);
console.log(newArray) // [3, 4]
6. 배열 요소 위치 찾기
/**
*
*/
indexOf(searchElement: T, fromIndex?: number): number;
/**
*
*/
lastIndexOf(searchElement: T, fromIndex?: number): number;
let array: Array<string> = ["a","b","c","d","c","a"];
let indexC = array.indexOf("c");
console.log(indexC); // 2
let lastA = array.lastIndexOf("a");
console.log(lastA); // 5
7. 연결 배열 요소
/**
*
*/
join(separator?: string): string;
let array: Array<string> = ["a","b","c","d","c","a"];
let result = array.join();
console.log(result); // a,b,c,d,c,a
result = array.join("+");
console.log(result); // a+b+c+d+c+a
result = array.join("");
console.log(result); // abcdca
8. 정렬, 역순 배열
let array:Array = [3, 2, 1, 8, 7, 0, 4];
console.log(array); // [3, 2, 1, 8, 7, 0, 4]
array.sort();
console.log(array); // [0, 1, 2, 3, 4, 7, 8]
array.reverse();
console.log(array); // [8, 7, 4, 3, 2, 1, 0]
여기 전편 을 보 세 요
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Cypress에서 Stripe Elements의 자동 테스트 수행을 사용하여 E2E 테스트를 작성할 때 약간의 고려가 필요했기 때문에 비망으로 남겨 둡니다 ✍️ 을 사용하여 이런 코드에서 카드 번호 입력 요소를 만들었습니다. 본래라면, 카드 정보의 입력이 다른 도메인(Stripe...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.