简体   繁体   English

Javascript 循环通过嵌套的 object 并尝试查看所有值是否相同

[英]Javascript loop through a nested object and trying to see if all values are same or not

const tree = {
  a : 1,
  b : 1,
  c : {
    a1 : 1,
    b1 : 2
  }
}

Here is a sample object in javascript.这是 javascript 中的示例 object。 Is there a way to write a function and trying to see if every node's value in this object is the same or not?有没有办法编写 function 并尝试查看此 object 中每个节点的值是否相同? if is all same return true otherwise return false.如果都相同,则返回 true,否则返回 false。 (The deep of the object can be infinite) (object的深度可以无限大)

const tree = {
  a : 1,
  b : 1,
  c : {
    a1 : 1,
    b1 : 2
  }
}

Here is a sample object in javascript.这是 javascript 中的示例 object。 Is there a way to write a function and trying to see if every node's value in this object is the same or not?有没有办法编写 function 并尝试查看此 object 中每个节点的值是否相同? if is all same return true otherwise return false.如果都相同,则返回 true,否则返回 false。 (The deep of the object can be infinite) (object的深度可以无限大)

const tree = {
  a : 1,
  b : 1,
  c : {
    a1 : 1,
    b1 : 2
  }
}

Here is a sample object in javascript.这是 javascript 中的示例 object。 Is there a way to write a function and trying to see if every node's value in this object is the same or not?有没有办法编写 function 并尝试查看此 object 中每个节点的值是否相同? if is all same return true otherwise return false.如果都相同,则返回 true,否则返回 false。 (The deep of the object can be infinite) (object的深度可以无限大)

const tree = {
  a : 1,
  b : 1,
  c : {
    a1 : 1,
    b1 : 2
  }
}

Here is a sample object in javascript.这是 javascript 中的示例 object。 Is there a way to write a function and trying to see if every node's value in this object is the same or not?有没有办法编写 function 并尝试查看此 object 中每个节点的值是否相同? if is all same return true otherwise return false.如果都相同,则返回 true,否则返回 false。 (The deep of the object can be infinite) (object的深度可以无限大)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM