Reputation: 55
I'm Trying to send tag's ID in a array as tags will be multiple for a single blog.
const tagsList = data.tags.map((item: {
value: number;
label: string;
}) => {
return {
label: item.label, value: item.value
}
here is the structure of data.tags
}
)
details.append('tags', tagsList)
I'm Trying in this way but i'm unable to do so
Can anyone help me sending the ids of tags in an array? Thanks in advance
Upvotes: 0
Views: 75
Reputation: 722
Here's a the code:
There's an array of objects that include tags - a label
and value
for each tag. (Yours is called data.tags
).
We declare a const tagsList
, and use the map
method on tags to return only the value
in each tag.
Your use of map
was inaccurate, you don't really have to pass the structure of each tag into the map
method. Feel free to check out how map works here.
Let me know if the code works for you :)
const tags = [{value:8,label:'2'},{value:10,label:'2'}]
const tagsList = tags.map((item) => {
return item.value
})
console.log(tagsList)
Upvotes: 1