简体   繁体   中英

jQuery Error: Var is defined but says that its not defined?

here is my source

var linkData = Array();

$.each(links, function(index){
    var obj =   { 
                    link: links[index].href,
                    name: links[index].innerHTML
                };

    linkdata.push(obj);
});
console.log(linkData);

this is the error

Uncaught ReferenceError: linkdata is not defined 

but its declaired....

what am i doing wrong ?!?!?

i tried to declaire it like

var linkData = Array();
linkData = Array();
var linkData = [];
linkData = [];

no changes...

Change

linkdata.push(obj);

to

linkData.push(obj);

It's Key sensitive is linkData instead of linkdata .

var linkData = Array();

$.each(links, function(index){
    var obj =   { 
                    link: links[index].href,
                    name: links[index].innerHTML
                };

    linkData.push(obj); //you had linkdata
});
console.log(linkData);

linkData不是linkdata ,请纠正

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM