可能是语法错误但无法找到 [英] Maybe a syntax error but cant find

查看:76
本文介绍了可能是语法错误但无法找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var friends= {
    steve: {
    firstName: "steve",
    lastName: "Sonwane",
    number: "9867707997",
    address: ['bld.no 234 N.C.H colony']
    },
    sunil: {
    firstName: "Sunil",
    lastName: "Sonwane",
    number: "9768912320",
    address: ['bld.no 234 t.C.H colony']
    },
};
  
    
var list = function(friends){
    for(var key in friends){
        console.log(key);
        }
        };
    
var search= function(name) { 
    for (var key in friends) {
        if (friends[key].firstName === name) { 
            console.log(friends[key]);
            return friends[key];
        } else {
            console.log("couldn't find them");
        }
    }
};

search("steve")

< br $> b $ b

我尝试了什么:



尝试将对象结构更改为类似friends.steve = {then key's ad values}



但是没有用!也许是语法错误!



What I have tried:

tried changing object structure to something like friends.steve = {then key's ad values}

but did'nt work ! maybe a syntax error !

推荐答案

仔细查看数据结构的末尾。看起来你有一个比你需要的逗号更多。



地址字符串看起来有点奇怪。方括号怎么样?尝试将它们更改为,例如,bld.no 234 NCH colony。



我认为朋友 不是 意味着是一个JSON结构。 如果 那么开始和结束的花括号应该是方形[]。



var friends = {

史蒂夫:{

firstName:史蒂夫,

lastName:Sonwane,

数字: 9867707997,

地址:['bld.no 234 NCH colony']

},

sunil:{

firstName:Sunil,

lastName:Sonwane,

编号:9768912320,

地址:['bld。没有234 tCH殖民地']

},< ----。流浪逗号?

};
Look very carefully at the end of the data structure. Looks like you have a comma more than you need.

The address strings also look a little odd. What's with the square brackets? Try changing them to, for example, "bld.no 234 N.C.H colony".

I take it that friends isn't meant to be a JSON structure. If it is then the opening and closing curly brackets should be square [].

var friends= {
steve: {
firstName: "steve",
lastName: "Sonwane",
number: "9867707997",
address: ['bld.no 234 N.C.H colony']
},
sunil: {
firstName: "Sunil",
lastName: "Sonwane",
number: "9768912320",
address: ['bld.no 234 t.C.H colony']
}, <----. Stray comma?
};


这篇关于可能是语法错误但无法找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆