I've been banging my head against a wall with this all day, I've looked at other questions and they all say use JSON.parse or something similar, but I can't get anything to work for the life of me.
I have an object stored as text in a PostGres DB:
{149804: [75319, 2887526, 2938701],3136977: [3482061,3482062]}
I have to read it into a variable and go through it's properties but i can't get it to work, if I do a JSON.parse I get a "SyntaxError: Unexpected number" on the first number {1...}.
I tried looking at the object properties without doing a parse to test it, but it keeps saying it doesn't have that property (with and without ' around the number in case):
if(selectedItems.hasOwnProperty(149804)){
console.log("HAS 149804");
}else{
console.log("DOESN'T HAVE 149804");
};
What am I doing wrong here?
eval(0|| ... )it instead ofJSON.parse(...), but it will be slightly slower. if you don't fill the database, then be careful usingeval. you can probably also use a RegExp to "fix" the JSON into something that can be parse()ed.