gpt4 book ai didi

javascript - 循环对象值

转载 作者:行者123 更新时间:2023-11-30 12:19:06 24 4
gpt4 key购买 nike

<分区>

我有一个要循环的对象。我正在做与数组相同的事情,但我似乎无法用对象完成它。这里:

var friends = {};
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['1 Infinite Loop','Cupertino','CA','95014']

};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "(408) 555-5555",
address: ['1 Infinite Loop','Cupertino','CA','95014']

};

function search(name){
for(x=0; x<friends.length; x++){

if(friends[x].firstName===name){
console.log(friends[x]);
return friends[x];
}
}

}

search("Steve");

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com