【发布时间】:2017-07-19 11:37:31
【问题描述】:
我用 Node js 写了一个返回这个的代码:
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 实现吗?
我之前使用了 stringify,这是输出:
{ 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' } } ] } ] }
【问题讨论】:
-
很好地解释了如何访问对象/数组属性 - stackoverflow.com/questions/11922383/…
-
您可以通过索引访问数组(entries[0].data
-
@Kevin.a 你可以在下面查看我的代码。它将在您的整个对象中起作用。
标签: javascript node.js