how can I get "title" from this json array in javascript? I want to get all of "title"s from this json array and put them into another array like this :
array(
`hey title1`,
`hey title2`,
...
)
but I don't know how many titles we are going to get and i think it's possible with 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'
}
}
thank you for your help
CodePudding user response:
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
}
})
here is a simple one i added the id property to know which ones title it is