join()方法就是将array数据中每个元素都转为字符串,用自定义的连接符分割

1、join(”)将数组元素无缝拼接

let s = Array('a','p','p','l','e')document.write(s.join('')) 

输出结果:apple

2、join(‘ ‘) 将数组元素以空格分割

let s = Array('Apple','is','on','my','table')document.write(s.join(' '))

输出结果:Apple is on my table

3、join()将数组每个元素都转为字符串,用法等同于toString()

let s = Array(1,2,3)console.log(s)console.log(s.join())

4、join()将数组转换为页面元素的内容

Document 
    let data = ['第一个','第二个','第三个','第四个']let list = document.querySelector('#list')let content = '
  • ' + data.join('
  • ') + '
  • 'list.innerHTML = content

    案例代码

    Document
    id书名作者出版社操作
    let tb = document.querySelector('#tb')data = [{id:1, bookname:'红楼梦', author:'曹雪芹', publisher:'河南出版社'},{id:2, bookname:'活着', author:'余华', publisher:'海南出版社'},{id:3, bookname:'我与地坛', author:'史铁生', publisher:'湖南出版社'}]let content = []for(i = 0; i < data.length; i++){ content.push(''+data[i].id+''+data[i].bookname+''+data[i].author+''+data[i].publisher+'删除') tb.innerHTML = content.join('')}