相关疑难解决方法(0)

在JavaScript对象数组中按id查找对象

我有一个数组:

myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.]
Run Code Online (Sandbox Code Playgroud)

我无法改变数组的结构.我正在传递id 45,我想'bar'在数组中获取该对象.

如何在JavaScript或使用jQuery中执行此操作?

javascript arrays jquery object javascript-objects

1435
推荐指数
25
解决办法
131万
查看次数

在JSON对象上使用jQuery的find()

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)

jquery jquery-selectors

70
推荐指数
3
解决办法
24万
查看次数