var a = array.get(0);
这在jQuery脚本中不起作用,我收到错误array.get is not a function
。
答案 0 :(得分:0)
.get()
是jQuery对象上的方法,而不是数组对象上的方法。
// create jQuery object that contains references to all menus
var menus = $(".menu");
// get a regular array of DOM elements out of that jQuery object
var menuArray = menus.get();
// iterate that regular array
menuArray.forEach(function(item) {
console.log(item);
});
如果您已有数组,则只需使用数组语法访问数组元素:
var x = [1,2,3];
console.log(x[0]); // 1