[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McGeSringArray
Class: McGeStringArray
2d.McGeStringArray
Array representing strings
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new McGeStringArray(imp?
)
Constructor.
Parameters
Name | Type | Description |
---|---|---|
imp? | Object | Internal constructor |
Example
ts
import { McGeStringArray } from "mxcad";
//Create a new instance of McGeSringArray
const myArray = new McGeStringArray();
//Initialize McGeSringArray by passing in an object
const initialValues = { data: ["apple", "banana", "orange"] };
const myArray2 = new McGeStringArray(initialValues);
Properties
imp
• imp: any
Internal implementation object
Methods
append
▸ append(val
): void
Add a value
Parameters
Name | Type | Description |
---|---|---|
Val | string | string |
Returns
void
Example
ts
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
at
▸ at(index
, decodeFromGb2312?
): string
Obtain the values of data elements based on the array index
Parameters
Name | Type | Default value | Description |
---|---|---|---|
Index | number | undefined | array index |
decodeFromGb2312 | boolean | true | - |
Returns
string
character string
Example
ts
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
console.log(array.at(0)); // Output: "apple"
console.log(array.at(1)); // Output: "banana"
clear
▸ clear(): void
Clear the array
Returns
void
Example
ts
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
array.clear();
console.log(array.length()); // Output: 0
copy
▸ copy(val
): McGeStringArray
Copy the value of the object
Parameters
Name | Type |
---|---|
val | McGeStringArray |
Returns
Example
ts
import { McGeStringArray } from "mxcad";
const array1 = new McGeStringArray();
const array2 = new McGeStringArray();
array2.append("apple");
array2.append("banana");
//Copy the value of array2 to array1
array1.copy(array2);
forEach
▸ forEach(call
, decodeFromGb2312?
): void
Traverse the array
Parameters
Name | Type | Default value | Description |
---|---|---|---|
Call | (val: string, index: number)=>void | undefined | callback function |
decodeFromGb2312 | boolean | true | - |
Returns
void
Example
ts
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
array.forEach((val, index) => {
console.log(`Index ${index}: Value ${val}`);
});
//Output:
// Index 0: Value apple
// Index 1: Value banana
length
▸ length(): number
Return the length of the array
Returns
number
Array length
Example
ts
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
console.log(array.length()); // Output: 0
setAt
▸ setAt(index
, val
, decodeFromGb2312?
): void
Set the value of data elements through array indexing
Parameters
Name | Type | Default value | Description |
---|---|---|---|
Index | number | undefined | array index |
Val | string | undefined | string |
decodeFromGb2312 | boolean | true | - |
Returns
void
Example
ts
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
array.setAt(0, "orange");
console.log(array.at(0)); // Output: "orange"