我有一个数组:
myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.]
Run Code Online (Sandbox Code Playgroud)
我无法改变数组的结构.我正在传递id 45,我想'bar'在数组中获取该对象.
如何在JavaScript或使用jQuery中执行此操作?
我之前已经问过类似的问题,但这个问题有点不同.我有一个未命名的对象数组,其中包含一个命名对象数组,我需要获取"name"为"string 1"的对象.这是一个示例数组.
var array = [
{ name:"string 1", value:"this", other: "that" },
{ name:"string 2", value:"this", other: "that" }
];
Run Code Online (Sandbox Code Playgroud)
更新:我应该早些说过,但是一旦找到它,我想用一个编辑过的对象替换它.
假设我有一个对象:
[
{
'title': "some title"
'channel_id':'123we'
'options': [
{
'channel_id':'abc'
'image':'http://asdasd.com/all-inclusive-block-img.jpg'
'title':'All-Inclusive'
'options':[
{
'channel_id':'dsa2'
'title':'Some Recommends'
'options':[
{
'image':'http://www.asdasd.com' 'title':'Sandals'
'id':'1'
'content':{
...
Run Code Online (Sandbox Code Playgroud)
我想找到id为1的一个对象.是否有类似这样的函数?我可以使用Underscore的_.filter方法,但我必须从顶部开始并过滤掉.
我正在寻找php这个问题的已接受答案中提到的解决方案:
javascript - 返回父级,只有与嵌套对象的对象数组中的给定搜索字符串匹配的子级
请找到以下代码:
<?php
$items = array(
'tableData' => array
(
array
(
'booking_name' => 'abc/xyz/123',
'pdg' => 'assure',
'user_area' => 'es st1',
'release' => 'oss72',
'start_date' => '2017-06-20 00:00:00',
'end_date' => '2017-06-23 00:00:00',
'asset_info' => array
(
array
(
'status' => 10,
'manufacturer' => 'Oracle',
'model' => 'HP BL460C GEN8',
'hardware_color' => '#0066b3',
),
array
(
'status' => 11,
'manufacturer' => 'HP',
'model' => 'HP BL460C GEN81',
'hardware_color' => '#0066b3',
)
),
'full_name' => 'Valay …Run Code Online (Sandbox Code Playgroud)