Javascript for循环不';完成整个对象长度的执行?
这是自由代码营中的一个赋值,这是我的代码,因为循环在第一次迭代时在0处停止,它没有完成,因为for循环的第一次迭代为true,我如何强制此代码完成循环以检查此对象数组的全部属性和值Javascript for循环不';完成整个对象长度的执行?,javascript,Javascript,这是自由代码营中的一个赋值,这是我的代码,因为循环在第一次迭代时在0处停止,它没有完成,因为for循环的第一次迭代为true,我如何强制此代码完成循环以检查此对象数组的全部属性和值 //Setup var contacts = [ { "firstName": "Akira", "lastName": "Laine", "number": "0543236543", "likes": ["Pizza", "Coding", "Brownie Points"] },
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUpProfile(firstName, prop) {
debugger;
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (!contacts[x].hasOwnProperty(prop)) {
return 'No such property';
}
if (contacts[x].firstName != firstName) {
return 'No such contact';
}
if (contacts[x].hasOwnProperty(prop) && contacts[x].firstName === firstName) {
return prop;
}
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Harry", "likes");
//设置
var触点=[
{
“名字”:“Akira”,
“姓氏”:“莱恩”,
“编号”:“0543236543”,
“喜欢”:[“披萨”、“编码”、“布朗尼点数”]
},
{
“名字”:“哈利”,
“姓氏”:“波特”,
“编号”:“0994372684”,
“喜欢”:[“霍格沃茨”、“魔法”、“海格”]
},
{
“名字”:“夏洛克”,
“姓氏”:“福尔摩斯”,
“编号”:“0487345643”,
“喜欢”:[“有趣的案例”,“小提琴”]
},
{
“名字”:“克里斯蒂安”,
“姓氏”:“Vos”,
“编号”:“未知”,
“喜欢”:[“Javascript”、“游戏”、“狐狸”]
}
];
函数lookUpProfile(firstName,prop){
调试器;
//仅更改此行下方的代码
对于(变量x=0;x
在循环中,只有当您有匹配项时,才应返回
。否则,您应继续:
当到达循环末尾时,表示没有匹配项,您可以返回特定的错误值:
function lookUpProfile(firstName, prop) {
debugger;
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (contacts[x].hasOwnProperty(prop) && contacts[x].firstName === firstName) {
return prop;
}
}
return 'No such contact';
// Only change code above this line
}
函数lookUpProfile(firstName,prop){
调试器;
//仅更改此行下方的代码
对于(变量x=0;x
在循环中,只有当您有匹配项时,才应返回
。否则,您应继续:
当到达循环末尾时,表示没有匹配项,您可以返回特定的错误值:
function lookUpProfile(firstName, prop) {
debugger;
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (contacts[x].hasOwnProperty(prop) && contacts[x].firstName === firstName) {
return prop;
}
}
return 'No such contact';
// Only change code above this line
}
函数lookUpProfile(firstName,prop){
调试器;
//仅更改此行下方的代码
对于(变量x=0;x
好吧,如果第一个返回函数finishesWell中需要,停止不返回此类属性和联系人,并将文本存储在变量中。如果第一个返回函数finishesWell中需要,停止不返回此类属性和联系人,并将文本存储在变量中