0

I've got this result from a query :

result

I convert it to an object with JSON.parse. Now I Want this object to be an array of string so that it can appear in vue-formular just like this :

Vue-formular

tag: ['tag_7z8eq73', 'tag_7v9aq73', 'tag_8gr6h5h', 'tag_5bh89vh', 'tag_0k4kl89'],

Do you know what is the right way to convert ?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Guts
  • 35
  • 7
  • 1
    Welcome to Stack Overflow! Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=javascript+convert+object+to+array+site%3Astackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Jul 27 '22 at 09:01
  • 1
    See if this helps, https://stackoverflow.com/questions/13973158/how-do-i-convert-a-javascript-object-array-to-a-string-array-of-the-object-attri – Shahzaib Jul 27 '22 at 09:03

2 Answers2

1

result_of_query = `[{"tag_property": ["tag_7z8eq73", "tag_7v9aq73", "tag_8gr6h5h", "tag_5bh89vk", "tag_0k4kl89"]}]`;
o = JSON.parse(result_of_query);
console.log(o[0].tag_property);
bjelli
  • 9,752
  • 4
  • 35
  • 50
0

let data = [{"key1": ["item1", "item2", "item3" ]} , {"key2": ["item1", "item2", "item3" ]}];
for(let i =0; i < data.length; i++){
  for(let [key, item] of Object.entries(data[i])){
        console.log(key, item)  
  }
}
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 28 '22 at 14:14