我怎样才能从这个 json 数组中获取标题? (javascript/discord.js)
how can i get just title from this json array? (javascript/discord.js)
如何从 javascript 中的 json 数组中获取“标题”?我想从这个 json 数组中获取所有“标题”并将它们放入另一个数组中,例如 this :
array(
`hey title1`,
`hey title2`,
...
)
但我不知道我们将获得多少标题,我认为使用 for
是可能的
{
data: [
{
id: '46475273517',
user_name: 'testtwo',
title: 'Hello this is my test for the eJx2',
is_set: true
},
{
id: '46471542013',
user_name: 'testone',
title: 'Hello this is my test for the eJx3',
is_set: false
},
{
id: '46474254233',
user_name: 'testthree',
title: 'Hello this is my test for the eJx7',
is_set: false
}
],
pagination: {
cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0'
}
}
感谢您的帮助
var arry = {
data: [ { id: '46475273517', user_name: 'testtwo', title: 'Hello this is my test for the eJx2', is_set: true }, { id: '46471542013', user_name: 'testone', title: 'Hello this is my test for the eJx3', is_set: false }, { id: '46474254233', user_name: 'testthree', title: 'Hello this is my test for the eJx7', is_set: false } ], pagination: { cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0' } }
var titles = arry.data.map((item) => {
return {
id: item.id,
title: item.title
}
})
这是一个简单的,我添加了 id 属性 以了解它是哪个标题
如何从 javascript 中的 json 数组中获取“标题”?我想从这个 json 数组中获取所有“标题”并将它们放入另一个数组中,例如 this :
array(
`hey title1`,
`hey title2`,
...
)
但我不知道我们将获得多少标题,我认为使用 for
是可能的 {
data: [
{
id: '46475273517',
user_name: 'testtwo',
title: 'Hello this is my test for the eJx2',
is_set: true
},
{
id: '46471542013',
user_name: 'testone',
title: 'Hello this is my test for the eJx3',
is_set: false
},
{
id: '46474254233',
user_name: 'testthree',
title: 'Hello this is my test for the eJx7',
is_set: false
}
],
pagination: {
cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0'
}
}
感谢您的帮助
var arry = {
data: [ { id: '46475273517', user_name: 'testtwo', title: 'Hello this is my test for the eJx2', is_set: true }, { id: '46471542013', user_name: 'testone', title: 'Hello this is my test for the eJx3', is_set: false }, { id: '46474254233', user_name: 'testthree', title: 'Hello this is my test for the eJx7', is_set: false } ], pagination: { cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0' } }
var titles = arry.data.map((item) => {
return {
id: item.id,
title: item.title
}
})
这是一个简单的,我添加了 id 属性 以了解它是哪个标题