请问js如何将字符串数组转换成单个字符串?

JavaScript09

请问js如何将字符串数组转换成单个字符串?,第1张

一、数组转字符串

需要将数组元素用某个字符连接成字符串,示例代码如下:

var a, b,c 

a = new Array(a,b,c,d,e) 

b = a.join('-') //a-b-c-d-e  使用-拼接数组元素c = a.join('') //abcde

二、字符串转数组

实现方法为将字符串按某个字符切割成若干个字符串,并以数组形式返回,示例代码如下:

var str = 'ab+c+de'var a = str.split('+') // [ab, c, de]

var b = str.split('') //[a, b, +, c, +, d, e]

var arr=[{ time: '2018-06', nikename: '任天野',money:88,type:'宣传码'},

{ time: '2018-07', nikename: '圣诞颂歌', money: 108, type: '商家码' },

{ time: '2018-07', nikename: '阿瑟人天翻地覆', money: 108, type: '商家码' },

{ time: '2018-08', nikename: '紫色的发', money: 88, type: '宣传码' },

],arr1=[]

arr.forEach(function(e,i){

   if(!arr1.some(function(e1){

      if(e1.idt==e.time){

         e1.items.push(e)

         return true

      }

   })){

      arr1.push({

         idt:e.time,

         items:[e]

      })

   }

})

console.log(arr1)