随着节点的js林写道,返回此代码:JavaScript中访问特定对象
entries:
[ { data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] },
{ data: [Object] } ] } null
代码:
targetingIdeaService.get({selector: selector}, function (error, result) {
var resultaten = result;
console.log(resultaten);
})
我的问题是,我如何访问这些数据。我记得在PHP中,你可以这样做:$object['data']
。
这是可能的JavaScript。
我字符串化之前使用,这是输出:
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike e85ba630' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '3718581' } } ] },
出所有这些数据我只是想获得第一和第二的价值。在这种情况下,这将是价值:'nike e85ba630'和'3718581。
我该怎么做?
其他信息:
{ totalNumEntries: 700,
entries:
[ { data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'red herring 9e23f4ad' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4574730' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 656e95f0' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '3442386' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'red herring 2bb32682' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '2641524' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike d4b589f6' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4778937' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike f10afc91' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4693893' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'red herring 8c856a44' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '6021387' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike d63a9577' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '5794059' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 4f21151' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4579430' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 64b804ed' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '6190489' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'red herring f4e7622a' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '6469058' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'red herring f59a9380' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '5207137' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 2b886e20' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4274335' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike a5874a43' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '5289335' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 49914ecd' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4007549' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 38d6b6c2' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '2965677' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 6fc88361' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4060879' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'red herring f8f4ee95' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4771620' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike 4fafb3a0' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '5501852' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'nike e85ba630' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '3718581' } } ] },
{ data:
[ { key: 'KEYWORD_TEXT',
value:
{ attributes: { 'xsi:type': 'StringAttribute' },
'Attribute.Type': 'StringAttribute',
value: 'red herring 59bd66ea' } },
{ key: 'SEARCH_VOLUME',
value:
{ attributes: { 'xsi:type': 'LongAttribute' },
'Attribute.Type': 'LongAttribute',
value: '4529457' } } ] } ] }
如何存取权限对象/数组属性很好的解释 - https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json – Diego
您可以访问阵列(<<< ----这是你所拥有的)条目的索引。 'entries [0] .data' – baao
@ Kevin.a你可以在下面查看我的代码。它会在整个对象中工作。 – Kamesh