你好我在JavaScript中有一个包含这个的对象:
{Coc Coc={30daysAgo=1}, Mozilla={30daysAgo=1}, BlackBerry={30daysAgo=1}, Safari={30daysAgo=140}, Firefox={30daysAgo=192}, YaBrowser={30daysAgo=6}, Internet Explorer={30daysAgo=72}, Safari (in-app)={30daysAgo=40}, Android Browser={30daysAgo=3}, Chrome={30daysAgo=1387}, SeaMonkey={30daysAgo=1}, Edge={30daysAgo=7}, Opera={30daysAgo=7}}
如何在变量中只插入没有其余浏览器的浏览器名称?
例如var browsers = Mozilla,BlackBerry,Safari等...
答案 0 :(得分:1)
试试这个:
var a = {"Coc Coc":{"30daysAgo":1}, Mozilla:{"30daysAgo":1}, BlackBerry:{"30daysAgo":1}, Safari:{"30daysAgo":140}, Firefox:{"30daysAgo":192}, YaBrowser:{"30daysAgo":6}, "Internet Explorer":{"30daysAgo":72}, "Safari (in-app)":{"30daysAgo":40}, "Android Browser":{"30daysAgo":3}, Chrome:{"30daysAgo":1387}, SeaMonkey:{"30daysAgo":1}, Edge:{"30daysAgo":7}, Opera:{"30daysAgo":7}};
var browsers = Object.keys(a).join(",");
结果:
Coc Coc,Mozilla,BlackBerry,Safari,Firefox,YaBrowser,Internet Explorer,Safari(应用内),Android浏览器,Chrome,SeaMonkey,Edge,Opera
的 Fiddle 强>