How do I wrap an array with a string?

Asked 2 years ago, Updated 2 years ago, 72 views

Based on Chrome

var a = ["abc", "def", "ghi"];

If you make it like this

["abc", "def", "ghi"]

You know... But this

'["abc", "def", "ghi"]'

Is there a function that makes it into a string?

javascript array string html css

2022-09-22 18:46

3 Answers

Js array can be made in JSON form using stringify.

var arr = [ "John", "Peter", "Sally", "Jane" ];
var myJSON = JSON.stringify(arr);

Source


2022-09-22 18:46

You can use the join function. Refer to Related lecture .

var a = ["abc", "def", "ghi"]
print(''.join(a))


2022-09-22 18:46

I understand that if you are going to forward it to JSON.parse() in javascript, you should write dumps.

import json
mylist = ['a', 'b', 'c']
result = json.dumps(mylist)

Please forward this result to JSON.parse().


2022-09-22 18:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.