You can use JSON.parse:
JSON.parse('[{ "qty" : "2","name" : "ice cream","price" : "25"},{ "qty" : "5","name" : "biriyani","price" : "250"},{ "qty" : "1","name" : "kappa","price" : "50"}]')
Notice that I addded square brackets around your string since there are three objects in it.
Answer from Shai on Stack OverflowVideos
Note: This is not unicode compliant.
"IU".split('')results in the 4 character array["I", "οΏ½", "οΏ½", "u"]which can lead to dangerous bugs. See answers below for safe alternatives.
Just split it by an empty string.
var output = "Hello world!".split('');
console.log(output);
See the String.prototype.split() MDN docs.
As hippietrail suggests, meder's answer can break surrogate pairs and misinterpret βcharacters.β For example:
// DO NOT USE THIS!
const a = 'ππππ'.split('');
console.log(a);
// Output: ["οΏ½","οΏ½","οΏ½","οΏ½","οΏ½","οΏ½","οΏ½","οΏ½"]
I suggest using one of the following ES2015 features to correctly handle these character sequences.
Spread syntax (already answered by insertusernamehere)
const a = [...'ππππ'];
console.log(a);
Array.from
const a = Array.from('ππππ');
console.log(a);
RegExp u flag
const a = 'ππππ'.split(/(?=[\s\S])/u);
console.log(a);
Use /(?=[\s\S])/u instead of /(?=.)/u because . does not match
newlines. If you are still in ES5.1 era (or if your browser doesn't
handle this regex correctly - like Edge), you can use the following alternative
(transpiled by Babel). Note, that Babel tries to also handle unmatched
surrogates correctly. However, this doesn't seem to work for unmatched low
surrogates.
const a = 'ππππ'.split(/(?=(?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|\uD800-\uDBFF|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/);
console.log(a);
A for ... of ... loop
const s = 'ππππ';
const a = [];
for (const s2 of s) {
a.push(s2);
}
console.log(a);