admin管理员组文章数量:1314015
using the following code
$.getJSON('services/getCharts.php', function(json) {
var $line1 = [];
$.each(json.posts, function() {
$line1 = $line1.push([this.post.rectime,this.post.actual_value]);
});
...
});
with JQuery gives me the following error:
Uncaught TypeError: Object 1 has no method 'push'
Could anyone help me finding what is wrong? Thanks a lot
using the following code
$.getJSON('services/getCharts.php', function(json) {
var $line1 = [];
$.each(json.posts, function() {
$line1 = $line1.push([this.post.rectime,this.post.actual_value]);
});
...
});
with JQuery gives me the following error:
Uncaught TypeError: Object 1 has no method 'push'
Could anyone help me finding what is wrong? Thanks a lot
Share Improve this question asked Apr 3, 2013 at 16:07 vpxvpx 3821 gold badge5 silver badges14 bronze badges 1-
MDN
.push()
method "Mutates an array by appending the given elements and returning the new length of the array." – user1106925 Commented Apr 3, 2013 at 16:20
3 Answers
Reset to default 6Replace
$line1 = $line1.push([this.post.rectime,this.post.actual_value]);
with
$line1.push([this.post.rectime,this.post.actual_value]);
push changes the receiver array and returns the new length.
You get this precise error message because the length (1
) is promoted as a Number
when you try to call the push
method on it.
The push
method returns the new length of the array, not a new array and it modifies the array it is being called upon:
$.each(json.posts, function() {
$line1.push([this.post.rectime,this.post.actual_value]);
});
here's a really tight syntax:
return Array.reduce(things, function(total, thing) {
return total.concat([thing]);
}, [])
This:
return total.concat([result])
Is similar in effects to this:
total.push(result);
return total;
本文标签: javascriptHow to solve quothas no method 39push39quot errorStack Overflow
版权声明:本文标题:javascript - How to solve "has no method 'push'" error? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741959913a2407212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论