var str = "剧情,犯罪,月黑风高"
/*
var arr = [
{name:"剧情"}
...
]
*/
var arr = []
var test = str.split(",")
for(var i=0;i<test.length;i++){
var name = test[i]
var obj = {
name
}
arr.push(obj)
}
console.log(arr);
var obj = {
top250:["你好666","他的666"],
comingSoon:["防抖111","节流111"],
theaters:["放大镜222","防静电222"]
}
/*
var arr = [
{name:"你好"}
]
*/
var arr = []
for(let v in obj){
arr.push(...obj[v])
}
var res = arr.map(item=>{
item = item.replace(/\d/g,"")
return {item}
})
console.log(res);
var str = `<span>9.7<span><span>-248人评价</span><br>
<span>9.5<span><span>-48人评价</span><br>
<span>9.6<span><span>-508人评价</span>`
var arr = str.split("<br>")
var res = arr.map(item=>{
return item.replace(/<[^<>]+>/g,"").trim()
})
var test = []
var list = []
res.forEach(item=>{
test.push(item.split("-"))
})
test.forEach(item=>{
var star = item[0]
var rating = item[1].replace(/[^\d]/g,"")
list.push({star,rating})
})
console.log(list);
// Object.keys()可以获取对象所有的属性
// Object.values()可以获取对象所有属性的值
var obj = {
name:"李四",
age:39
}
var keys = Object.keys(obj)
var values = Object.values(obj)
console.log(keys);
console.log(values);
var last = `
[
{"name":"李四666","data":[2019,10,11]},
{"name":"张三666","data":[2017,10,11]},
{"name":"王五666","data":[2018,10,11]}
]
`
/*
var arr = [
{name:"李四...",data:"2019-10-11"}
...
]
*/
var test = JSON.parse(last)
var arr = []
test.forEach(item=>{
var {name,data} = item
name = name.replace(/\d/g,"")+"..."
data = data.join("-")
arr.push({name,data})
})
console.log(arr);
var arr = [
{name:"lisi"},
{name:"html"},
{name:"css"},
{name:"vue"},
{name:"vue"},
{name:"html"},
]
/*
["lisi","html","css","vue"]
*/
var list = []
arr.forEach(item=>{
var {name} = item
if(!list.includes(name)){
list.push(name)
}
})
console.log(list);
var arr = {
A:[{city:"武汉"},{city:"广州"}],
B:[{city:"深圳"},{city:"广州"}],
C:[{city:"上海"},{city:"武汉"}],
}
/*
["武汉","广州","深圳","上海"]
*/
var {A,B,C} = arr
var list = [...A,...B,...C]
var test = []
list.forEach(item=>{
var {city} = item
if(!test.includes(city)){
test.push(city)
}
})
console.log(test);