我有一个数组:
myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.]
Run Code Online (Sandbox Code Playgroud)
我无法改变数组的结构.我正在传递id 45,我想'bar'在数组中获取该对象.
如何在JavaScript或使用jQuery中执行此操作?
与brnwdrng的问题类似,我正在寻找一种搜索类似JSON的对象的方法.
假设我的对象的结构是这样的:
TestObj = {
"Categories": [{
"Products": [{
"id": "a01",
"name": "Pine",
"description": "Short description of pine."
},
{
"id": "a02",
"name": "Birch",
"description": "Short description of birch."
},
{
"id": "a03",
"name": "Poplar",
"description": "Short description of poplar."
}],
"id": "A",
"title": "Cheap",
"description": "Short description of category A."
},
{
"Product": [{
"id": "b01",
"name": "Maple",
"description": "Short description of maple."
},
{
"id": "b02",
"name": "Oak",
"description": "Short description of oak."
},
{
"id": …Run Code Online (Sandbox Code Playgroud)