Skip to content
On this page

mxcad_2d API 文档 / 2d / McGeStringArray

Class: McGeStringArray

2d.McGeStringArray

表示字符串的数组

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new McGeStringArray(imp?)

构造函数。

Example

ts
import { McGeStringArray } from "mxcad";

  // 创建一个新的 McGeStringArray 实例
  const myArray = new McGeStringArray();

  // 通过传入一个对象初始化 McGeStringArray
  const initialValues = { data: ["apple", "banana", "orange"] };
  const myArray2 = new McGeStringArray(initialValues);

Parameters

NameTypeDescription
imp?object内部构造函数

Properties

imp

imp: any

内部实现对象

Methods

append

append(val): void

添加一个值

Example

ts
import { McGeStringArray } from "mxcad";

const array = new McGeStringArray();
  array.append("apple");
  array.append("banana");

Parameters

NameTypeDescription
valstring字符串

Returns

void


at

at(index, decodeFromGb2312?): string

根据数组索引得到数据元素的值

Example

ts
import { McGeStringArray } from "mxcad";

  const array = new McGeStringArray();
  array.append("apple");
  array.append("banana");

  console.log(array.at(0)); // 输出: "apple"
  console.log(array.at(1)); // 输出: "banana"

Parameters

NameTypeDefault valueDescription
indexnumberundefined数组索引
decodeFromGb2312booleantrue-

Returns

string

字符串


clear

clear(): void

清空数组

Example

ts
import { McGeStringArray } from "mxcad";

  const array = new McGeStringArray();
  array.append("apple");
  array.append("banana");

  array.clear();
  console.log(array.length()); // 输出: 0

Returns

void


copy

copy(val): McGeStringArray

复制对象的值

Example

ts
import { McGeStringArray } from "mxcad";

  const array1 = new McGeStringArray();
  const array2 = new McGeStringArray();
  array2.append("apple");
  array2.append("banana");

  // 复制 array2 的值到 array1
  array1.copy(array2);

Parameters

NameType
valMcGeStringArray

Returns

McGeStringArray


forEach

forEach(call, decodeFromGb2312?): 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}`);
  });
  // 输出:
  // Index 0: Value apple
  // Index 1: Value banana

Parameters

NameTypeDefault valueDescription
call(val: string, index: number) => voidundefined回调函数
decodeFromGb2312booleantrue-

Returns

void


length

length(): number

返回数组长度

Example

ts
import { McGeStringArray } from "mxcad";

const array = new McGeStringArray();
console.log(array.length()); // 输出: 0

Returns

number

数组长度


setAt

setAt(index, val, decodeFromGb2312?): 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)); // 输出: "orange"

Parameters

NameTypeDefault valueDescription
indexnumberundefined数组索引
valstringundefined字符串
decodeFromGb2312booleantrue-

Returns

void