Remove First and Last double Quotes from "["Morning Shift","Day Shift"]" [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to remove First and Last Quotes from this array Using JavaScript:
"["Morning Shift","Day Shift"]"
After Remove quotes output look like this
["Morning Shift","Day Shift"]

You can try using JSON.parse():
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.
Demo:
var data = `["Morning Shift","Day Shift"]`;
data = JSON.parse(data);
console.log(data);

Related

How to parse object array that has been stringified using backslashes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
I have been searching for the correct regex for converting this string to JSON. It works if there is a single object in the array, but I believe the comma is messing it up somehow.
const json = "{\"userId\":44, \"userName\": \"Jim Coleman\"},{\"userId\":33515, \"userName\": \"Grace Mamaradlo\"}";
const obj = JSON.parse(json.replace(/("[^"]*"\s*:\s*)(\d{17,})/g, '$1"$2"'));
console.log(obj);
There was nothing wrong except that the list of objects was not contained within square brackets
const json = "{\"userId\":44, \"userName\": \"Jim Coleman\"},{\"userId\":33515, \"userName\": \"Grace Mamaradlo\"}";
console.log(JSON.parse(`[${json}]`))

How do I remove double quote "" from JSON Value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am doing my Javascript. And just imported JSON and printed it out with JSON.stringfy
I am using that site because the JSON contains the URL which I want to link.
I am not getting what I really need as the output.
description": "www.site.com"
This is what I get in my console:
"www.site.com"
This is what I actually want, and remove the quotes.
www.site.com
Please help!
Am not sure what your requirement is but you can do this.
Try Replace function;
const obj = {description: "www.site.com"};
JSON.stringify(obj.description).replace(/"/g,"");
var someStr = 'He said "Hello, my name is Foo"';
console.log(someStr.replace(/['"]+/g, ''));
That should do the trick... (if your goal is to replace all double quotes).

REMOVE SPECIFIC NUMBER WITH JS [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'M TRYING TO HANDLE THIS DATA IN JAVASCRIPT SO HOW CAN I REMOVE DATA ACCORDING TO THE ID NUMBER THE FIRST NUMBER
600030/01/2018/163904
600010/01/2014/3789
600030/01/2020/47104
600030/01/2012/39104
600010/01/2011/93817
how can i remove all 600030 data so i get
600010/01/2014/3789
600010/01/2011/93817
If all data shaped in Array and element is instance of String.
I would recommend Array.prototype.filter and String.prototype.startsWith();
let data = [
'600030/01/2018/163904',
'600010/01/2014/3789',
'600030/01/2020/47104',
'600030/01/2012/39104',
'600010/01/2011/93817',
];
let filteredData = data.filter((d)=>!d.startsWith('600030'));
console.log( filteredData );
Result is
[
'600010/01/2014/3789',
'600010/01/2011/93817'
]

Why does JSON.parse() add numbers in front of elements? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a string where I build my build my "json-like" format, like
_toBeFormated =
[
{"foor":"bar","foo":"bar","foo":["bar,bar"]},
{"foor":"bar","foo":"bar","foo":["bar,bar"]},
{"foor":"bar","foo":"bar","foo":["bar,bar"]}
]
But after calling JSON.parse like _afterFormat = JSON.parse(_toBeFormated), my structure looks like the following:
_afterFormat =
0:{"foor":"bar","foo":"bar","foo":["bar,bar"]},
1:{"foor":"bar","foo":"bar","foo":["bar,bar"]},
2:{"foor":"bar","foo":"bar","foo":["bar,bar"]}
If I try to change to JSON Format at the beginning, like leaving out [ ], if failes to parse, also it looks like valid JSON to me. What am I missing, or why does it add the numbers at the beginning?
It doesn't add numbers. The data structure is an array. The tool you are using to look at the array is showing the index of each entry.

How to transform a string of maps coordinates into an array javascript? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am drawing trails on a map and the coordinates of the trail are saved as string in a json file in the following format:
(43.886758784865066, 24.226741790771484),(43.90271630763887, 24.234981536865234)
I need to get these values and add them to an array:
coordinates= [43.886758784865066, 24.226741790771484,43.90271630763887, 24.234981536865234];
So how can I do this transition?
You can try that way
var string = '(43.886758784865066, 24.226741790771484),(43.90271630763887, 24.234981536865234)';
string.match(/\d+(\.\d+)/g).map(function(d){return d;});
You could just use regular expressions to parse those strings.
const match = string.match(/\((.*)\, (.*)\),\((.*)\, (.*)\)/)
/*
Matches
["(43.886758784865066, 24.226741790771484),(43.90271630763887, 24.234981536865234)", "43.886758784865066", "24.226741790771484", "43.90271630763887", "24.234981536865234"]
*/
const Array.prototype.slice.call(match).splice(1, 4)
/* Converts to array and takes the last three elements
["43.886758784865066", "24.226741790771484", "43.90271630763887", "24.234981536865234"]
*/

Categories

Resources