Skip to content
Advertisement

How do I remove double quotes from a multidimensional array?

Q: Did you find the same question asked before?

A: Yes, here’s the link to the question exactly looks like mine but the answers are not applicable because it converts the string to a number.

Q: Why do you need to remove the double quotes?

A: Because I need to follow the syntax allowed for moment js.

Q: Did you try removing the double quotes from the provider/backend?

A: Yes, as you can see in the Backend Code snippet below, it didn’t work from what I tried (this question accepts solutions in either javascript or PHP).

Q: What have you tried using JavaScript?

A: I tried this one but it didn’t work as you will also see in the attachment.

JavaScript

enter image description here


Moving on to the actual code

This is where I will put the multidimensional array:

JavaScript

Backend Code:

JavaScript

EDIT

This edit provides the result of testing KooiInc’s code

JavaScript

Console result

enter image description here


EDIT #2

I’ve edited the question to show the result of KooiInc’s updated answer.

JavaScript

Now I remember why I’m trying to format the moment in my backend code because mapping the object is combining the moment’s time intervals into a single array like below, and because of this it completely ignores the 3rd and 4th moment time intervals and the 1st and 2nd-time intervals are only disabled.

Using the code above…

JavaScript

in this hardcoded moment time intervals, it’s not combining into a single array.

JavaScript

Advertisement

Answer

JSON (JavaScript Object Notation) is always a string representation. You can’t store function calls as function calls within it.

So, rethink your code and deliver another object you can use client side. Let the server deliver moments as an array of arrays, containing intervals ([begin, end]) and use moment client side.

Something like:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement