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