Array conversion issue

Hello friends,

I am trying (in Javascript an Coldfusion) to convert: {“val1”:“member”,“val2”:“book”,“val3”:“journal”,“val4”:“new_member”,“val5”:“cds”},
into this: { member,book,journal,new_member,cds}

Notice that I am trying to eliminate quotes.

Is it possible to achieve that? How can I do it?

Thanks
Tom

When you define an object, you need to associate the key and value in some way, so objects cannot work as you want there.

Currently the object you’re starting with would have its values access as obj.val1, obj.val2, etc…
Let’s start with finding out what data structure you are wanting, and why are you wanting to eliminate quotes?

Thank you for your reply. The reason that i need this ({member,book,journal,new_member,cds}) is that the search server i am using unfortunately consumes that kind of “datatype” (for querying). This obj: {“val1”:“member”,“val2”:“book”,“val3”:“journal”,“val4”:“new_member”,“val5”:“cds”} is the response that I got from the client. So, I end up with this:

var tata={"val1":"member","val2":"book","val3":"journal","val4":"new_member","val5":"cds"}
		var arr=[]
	
	for (var i in tata) {
		arr.push(tata[i])
	};
	
	console.log(arr);
	
	
	wrd = new Array(arr)
		var joinwrd = wrd.join(",");
	
	console.log('{' + joinwrd + '}');

Thank you

Ahh, so you want to end up with a string representation of the object values, right.

That can be done now in modern web browsers with:


var obj = {"val1": "member", "val2": "book", "val3": "journal", "val4": "new_member", "val5": "cds"},
    keys = Object.keys(obj),
    objValue = function (key) {
        return obj[key];
    },
    values = Array.prototype.map.call(keys, objValue);
console.log('{' + values.join(', ') + '}');

But the code you had there also does the same job.

Many thanks my friend