value1 = {a:5, b:6}, value2 = {a:8, b:7}; let a = Object.keys(value1), b = Object.keys(value2); for (let x = 0; x < a.length; x ++) { if (a[x] === b[x] && value1.a[x] === value2.b[x]) { console.log(a[x], b[x], value1.a[x], value2.b[x]); } } // -> a, a, undefined, undefined P.S. I know the other ways to compare objects; just wanted to find out why this doesn't work.
https://stackoverflow.com/questions/66717795/javascript-objects-why-are-value1-ax-and-value2-bx-returned-as-undefined-si March 20, 2021 at 10:50AM
没有评论:
发表评论