<script>
var str = `<span>9.7<span></span>-248人评价</span>
<br><span>9.5<span></span>-508人评价</span>
<br><span>9.6<span><span>-508人评价</span>`;
/*
arr = [
{star:9.7,rating:248},
{star:9.5,rating:48},
{star:9.6,rating:508},
]
<br>
将数组中的每一项html标签去除 9.7-248人评价
*/
var arr = str.split("<br>")
// console.log(arr)
var reg = /<[^<>]+>/g;
var res = arr.map(item=>{
//console.log(item.trim().replace(reg,""));
return item.trim().replace(reg,"")
});
//console.log(res);
var list = [];
res.forEach(item=>{
//console.log(item.split("-"))
list.push(item.split("-"))
})
var sum =[]
var rNum = /[^\d]/g;
list.forEach(item=>{
//console.log(item)
sum.push({
star:item[0],
rating:item[1].replace(rNum,"")
})
})
console.log(sum)
</script>