📌  相关文章
📜  javascript 对象通过数组中的键获取值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:16.443000             🧑  作者: Mango

代码示例4
function search(nameKey, myArray){
    for (var i=0; i < myArray.length; i++) {
        if (myArray[i].name === nameKey) {
            return myArray[i];
        }
    }
}

var array = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

var resultObject = search("string 1", array);