I have a string that I get in a jQuery callback and that looks like this 792-1816vh1,792-1816vh2 and I want to convert it to '792-1816vh1','792-1816vh2'. How can I do that? Any help appreciated, thanks.
So this is my problem:
I need to send some userid to a function, and that function is sending a push notification. And it works if the variable with the userid:s looks like "users" below, and is hardcoded in the js file. I also have two other variables with text.
var usersfromarray = strArray[2];//from a callback, not working
console.log(usersfromarray)//this writes 792-1816vh1,792-1816vh2
var users='792-1816vh1','792-1816vh2'//this is hardcoded in the js file.
var pushtext="Some text..."
var tid="now"
var str='792-1816vh1,792-1816vh2';
var res='';
str.split(',').forEach(function(elem) {
res += "'" + elem + "',";
});
// remove last ","
res = res.substring(0, res.length-1);
console.log(res);//this writes '792-1816vh1','792-1816vh2'
I send it to the function like this:
skickaPushnotiser([[pushtext,tid],users]);
If I use "users" then it is working, it sends the push.
If I use "res" then it is not working, even if it writes the same in the console as the "users".
Both "users" and "res" is writing: '792-1816vh1','792-1816vh2' in the console.
So why is "users" working and not "res"? I don´t know what Im missing? I would really appreciate some help, thanks.
Edit: I need "res" to be ["792-1816vh1", "792-1816vh2"], with the brackets and with " instead of ' Thanks.