【发布时间】:2014-06-27 17:11:04
【问题描述】:
我有一个具有 id 和类型值 ({ id: '23', kind: 'apple' }, { id: '35', kind: broccoli }) 的数组,但我有一个函数需要 id 的名称(假装 id 23 表示水果,id 35 表示蔬菜),例如“水果”或“蔬菜”。我写出一个不同的数组,其中包含 id 和 id 的名称 ({ id: '23', type: 'fruit' }, { id: '35', type: 'vegetable' })。如何过滤第一个数组,以便将 id 从 23 或 35 更改为水果或蔬菜?
【问题讨论】:
-
我可以使用 if else 语句或 switch case 语句,但必须有更简单的方法。
标签: javascript jquery arrays