更新时间:2023-12-01 09:27:04
您不需要的jQuery了点。使用常规的JavaScript
You don't need jQuery for that. Use regular javascript
var arr = new Array();
// or var arr = [];
arr.push('value1');
arr.push('value2');
请注意:在JavaScript中,你也可以使用对象为数组,但仍可以访问阵列原型。这使得对象的行为像一个数组:
Note: In javascript, you can also use Objects as Arrays, but still have access to the Array prototypes. This makes the object behave like an array:
var obj = new Object();
Array.prototype.push.call(obj, 'value');
将创建一个对象,看起来像:
will create an object that looks like:
{
0: 'value',
length: 1
}
您可以访问vaules就像一个正常的阵列f.ex OBJ [0]
。
You can access the vaules just like a normal array f.ex obj[0]
.