Unexpected comma using map()

前端 未结 3 1827
半阙折子戏
半阙折子戏 2020-12-02 16:34

I\'ve an array with a list of elements and I\'m trying to append this list to an HTML element using template strings:

3条回答
  •  借酒劲吻你
    2020-12-02 17:13

    .map() returns an array. You probably want to return a string containing the array elements concatenated together. You can do that with .join(''):

    var description = [
      'HTML & CSS',
      'Javascript object-oriented programming',
      'Progressive Web apps (PWAs)',
      'Website Performance Optimization',
      'Webpack and Gulp workflows',
      'Fullstack React.js',
      'Web Components',
      'Responsive web design',
      'Sketch design',
      'GraphQL and Relay'
    ]
    
    $('body').append(
      `
      
      ${description.map( function(work) { return `
    • ${work}
    • ` } ).join('') /* added .join('') here */}
    ` )

提交回复
热议问题