how to make object in array to be array [duplicate] - javascript

This question already has answers here:
Parsing string as JSON with single quotes?
(10 answers)
Parsing string as JSON with single quotes on key and keyvalue [duplicate]
(2 answers)
Converting array inside a string to an array
(2 answers)
Parsing "relaxed" JSON without eval
(6 answers)
Closed 1 year ago.
let origin = "[{'a':1, 'b':2}, {'a':3, 'b':4}, {'a':5, 'b':6}]"
let output = [{'a':1, 'b':2}, {'a':3, 'b':4}, {'a':5, 'b':6}]
How to make origin to be output as a array

Related

Get one or more string which starts and ends with into array [duplicate]

This question already has answers here:
Regular expression to extract text between square brackets
(15 answers)
Getting content between curly braces in JavaScript with regex
(5 answers)
Closed 3 years ago.
How to loop and get all string starts with { and ends with } into an array? For example:
Hi {recipient}, calling from {sender}. Your {item} has arrived.

How do i convert this string into an array? [duplicate]

This question already has answers here:
Parse JSON in JavaScript? [duplicate]
(16 answers)
Safely turning a JSON string into an object
(28 answers)
Closed 3 years ago.
I need to convert this string into a an array into the format shown below.
itemString
[{"_id":"1e12345","a":"abc","b":def","c":ghi"},{"_id":"1e678910","a":"xzx","b":sed","c":ert"}]
var item=itemString.split("},{").map(function(i){
return i
})
console.log(item)
what i need to get from from console.log(item)
0:{_id:"1e12345",a:"abc",b:"def",c:"ghi"}
1:{_id:"1e678910",a:"xzx",b:"sed",c:"ert"}
what i get from console.log(item)
0:"[{"_id":"1e12345","a":"abc","b":"def","c":"ghi""
1:""_id":"1e678910","a":"xzx","b":"sed","c":"ert"}]"

How to put variable into quotes? [duplicate]

This question already has answers here:
Double quote in JavaScript string
(4 answers)
How to interpolate variables in strings in JavaScript, without concatenation?
(17 answers)
How to insert variables in JavaScript strings?
(4 answers)
Closed 3 years ago.
Would like to put the variable ( txt.txt.charAt(char_counter) )in quotes.
Anyone can help?
Thanks
var pattern_node = document.createTextNode("Zeichen:"+txt.txt.charAt(char_counter)+" "+ str.str +" gesendet");
ES6/ES2015 feature, template string
var pattern_node = document.createTextNode(`Zeichen:${txt.txt.charAt(char_counter)} ${str.str} gesendet`);

Convert raw string to array [duplicate]

This question already has answers here:
How to convert an array like string to array in node.js?
(4 answers)
Closed 3 years ago.
I need to convert raw String to json array in javascript below the my logic
Original:
"[template1,template2]";
Exception:
"["template1","template2"]";
use slice to retrieve the text between the square brackets and then use split.
const input = "[template1,template2]";
const arr = input.slice(1, -1).split(',');
console.log(arr);

js list of strings to string [duplicate]

This question already has answers here:
Convert array to JSON
(12 answers)
Closed 4 years ago.
I need to convert list of strings
const ar: string[] = ['str1', 'str2']
to a string which contains ar container with square brackets [] and quotes "
const str: string = `["str1", "str2"]`
how to do it in proper way?
The format you want is a JSON array string. So use the JSON object's stringify function.
JSON.stringify(["some", "array", 123]);

Categories

Resources