【发布时间】:2010-12-31 14:16:28
【问题描述】:
如果两个值都不存在,我该如何推入一个数组?这是我的数组:
[
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" }
]
如果我尝试使用 name: "tom" 或 text: "tasty" 再次推送到数组中,我不希望发生任何事情......但如果它们都不存在,那么我希望它到 .push()
我该怎么做?
【问题讨论】:
-
使用字典(哈希/树)而不是数组。
-
这些都可以在 javascript 中使用吗?
-
使用Set
-
Set 不适用于对象数组
标签: javascript arrays json push not-exists