如何從 javascript 中的這個 json 陣列中獲取“標題”?我想從這個 json 陣列中獲取所有“標題”并將它們放入另一個陣列中,如下所示:
array(
`hey title1`,
`hey title2`,
...
)
但我不知道我們將獲得多少個頭銜,我認為有可能
{
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'
}
}
謝謝您的幫助
uj5u.com熱心網友回復:
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 屬性以知道它是哪個標題
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/481248.html
標籤:javascript 数组 json 不和谐.js
