我知道这很傻,但是:
window.temp1.targetInterests
返回我:
Object {Famosos: "Famosos", Musica: "Música", Humor: "Humor"}
我尝试join
:
window.temp1.targetInterests.join('/')
和map
:
window.temp1.targetInterests.map(function(elem){
return elem.name;
}).join(",");
但它一直让我回来
Uncaught TypeError: undefined is not a function
我做错了什么?
感谢。
答案 0 :(得分:1)
您可以使用Object.keys
将密钥加在一起:
var joinedKeys = Object.keys(window.temp1.targetInterests).join(",");
如果您想要实际值,则必须迭代对象:
var joinedValues = [];
for (var key in window.temp1.targetInterests) {
joinedValues.push(window.temp1.targetInterests[key]);
}
joinedValues = joinedValues.join(",");