我想过滤掉两个对象中常见的键值对。有两个对象:
first = {a:3 , b:4}
second = {a:5 , b:4}
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码来解决这个问题:
c = {}
for (const key of Object.keys(first)) {
for( const k of Object.keys(second)){
if ( key == k){
if (first[key]==second[k]){
c[key] = first[key]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这工作正常并给出输出 {b:4},但对于下面的测试输入值,我得到空对象作为输出,我不确定如何检查常见但不相等的值。
first = {a: 3, b: {x:7}};
second = {a: 4, b: {x: 7, y: 10}}
Run Code Online (Sandbox Code Playgroud)
这里的输出应该是:
{b: {x:7}}
Run Code Online (Sandbox Code Playgroud) 我在使用此命令时遇到问题:
ng add @ngrx/store@latest
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: ngstore-app@0.0.0
npm ERR! Found: @angular/core@13.0.0
npm ERR! node_modules/@angular/core
npm ERR! @angular/core@"~13.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"^12.0.0" from @ngrx/store@12.5.1
npm ERR! node_modules/@ngrx/store
npm ERR! @ngrx/store@"12.5.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or …Run Code Online (Sandbox Code Playgroud)