Home > front end >  Js a simple problem, bosses for help
Js a simple problem, bosses for help

Time:03-03

Var test=[];
For (var I=0; I & lt; 2; I++) {
Var info={headimg: "cc", js: "bb", uname: "oo"};
Var a=test. Includes (info);
The console. The log (a);
Test. Push (info);
Var b=test. Includes (info);
The console. The log (b);
}


Why the output is false, true, false, true
My understanding is false for the first time, because the info haven't added to the array of the test, but the second cycle test already has an info value, what is not true or false

CodePudding user response:

Two loop every time you create a new info object, the two objects are created by different address,
Includes methods to compare the two objects are compared by address, not according to the object that is,
Address different, two objects that are not equal, even if the two objects as content also not line,
  • Related