小编Bal*_*ong的帖子

如何在 Javascript 中仅过滤常见对象值

我想过滤掉两个对象中常见的键值对。有两个对象:

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)

javascript object filter key-value

2
推荐指数
1
解决办法
55
查看次数

使用 Angular 13 安装 ngrx 存储时出现错误,无法解析依赖关系树

我在使用此命令时遇到问题:

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)

node.js npm angular-cli angular

2
推荐指数
1
解决办法
6066
查看次数

标签 统计

angular ×1

angular-cli ×1

filter ×1

javascript ×1

key-value ×1

node.js ×1

npm ×1

object ×1