How can I change this :
{"position":4}
to this :
{"position":"4"}
Is there any simpe function (in javascript or node.js package), that puts quots around value ?
Maybe this (add quotation marks to the string):
var obj = {position: 4};
for (var p in obj)
obj[p] = '"' + obj[p] + '"';
Or this (convert number to string):
var obj = {position: 4};
for (var p in obj)
obj[p] = obj[p].toString();
I don't think there is any function as such but you may do it with something like:
EDIT: If you don't know the property value, do like this:
var test=new Object();
test.position="4";
for (var prop in test) {
test[prop]="\""+test[prop]+"\"";
alert(prop + " = " + test[prop]);
}
Check updated jsfiddle
i go whith 4+"" as that castes it to a string.
but you probly wanner rethink Why you need to cast your number to a string.