更新时间:2022-06-13 07:53:16
您不需要 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
}
您可以像普通数组 f.ex obj[0]
一样访问 vaule.
You can access the vaules just like a normal array f.ex obj[0]
.