Skip to content
On this page

mxcad_2d API 文档 / 2d / McGeLongArray

Class: McGeLongArray

2d.McGeLongArray

整数数组

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new McGeLongArray(imp?)

构造函数。

Example

ts
import { McGeLongArray } from "mxcad"

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

 // 通过传入一个对象初始化 McGeLongArray
 const initialValues = { data: [1, 2, 3, 4] };
 const myArray2 = new McGeLongArray(initialValues);

Parameters

NameTypeDescription
imp?object内部实现对象

Properties

imp

imp: any

内部实现对象

Methods

append

append(val): void

向数组中添加一个值

Example

ts
import { McGeLongArray } from "mxcad";

  const array = new McGeLongArray();
  array.append(5);
  array.append(10)

Parameters

NameTypeDescription
valnumber整数值

Returns

void


at

at(index): number

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

Example

ts
import { McGeLongArray } from "mxcad"

  const array = new McGeLongArray();
  array.append(5);
  array.append(10);

  console.log(array.at(0)); // 输出: 5
  console.log(array.at(1)); // 输出: 10

Parameters

NameTypeDescription
indexnumber数组索引

Returns

number

返回元素值


clear

clear(): void

清空数组

Example

ts
// array为整数数组
array.clear()

Returns

void


copy

copy(val): McGeLongArray

复制对象的值

Example

ts
import { McGeLongArray } from "mxcad"

  const array1 = new McGeLongArray();
  const array2 = new McGeLongArray();
  array2.append(10);
  array2.append(20);

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

Parameters

NameTypeDescription
valMcGeLongArray整数数组

Returns

McGeLongArray


copyFormAryId

copyFormAryId(aryId): McGeLongArray

从 McObjectId 数组中复制值

Example

ts
//objectIdArray 为一个对象id数组
  const array = new McGeLongArray();
  array.copyFormAryId(objectIdArray);

Parameters

NameTypeDescription
aryIdMcObjectId[]McObjectId 数组

Returns

McGeLongArray


forEach

forEach(call): void

遍历数组

Example

ts
import { McGeLongArray } from "mxcad"

  const array = new McGeLongArray();
  array.append(5);
  array.append(10);

  array.forEach((val, index) => {
    console.log(`Index ${index}: Value ${val}`);
  });
  // 输出:
  // Index 0: Value 5
  // Index 1: Value 10

Parameters

NameTypeDescription
call(val: number, index: number) => void回调函数

Returns

void


length

length(): number

返回数组长度

Example

ts
import { McGeLongArray } from "mxcad"

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

Returns

number

数组长度


setAt

setAt(index, val): void

通过数组索引设置数据元素的值

Example

ts
import { McGeLongArray } from "mxcad"

  const array = new McGeLongArray();
  array.append(5);
  array.append(10);

  array.setAt(0, 15);
  console.log(array.at(0)); // 输出: 15

Parameters

NameTypeDescription
indexnumber数组索引值
valnumber整数数值

Returns

void