js轉換整數陣列為字串陣列的方法

2021-10-16 18:02:55 字數 302 閱讀 9152

今天在專案裡遇到個這樣的bug,element的el-cascader控制項無法回顯資料,經過除錯後發現,是由於v-model所繫結的陣列元素,必須為字串型別才行,整數型別是無法回顯的,需要做一次轉換,

可以使用js陣列自帶的api進行轉換

array.map(string)

該api返回最新的字串陣列,例如:

原陣列  let arr = [1,2,3],經過arr1.map(string)轉換後,可以變成這樣let arr2 = ['1','2','3']

這樣el-cascader控制項就能 正確回顯資料了!

js物件 陣列轉換字串

物件轉換成字串需要使用tostring 方法。1 var a function 4 var b a.tostring 5 console.log a 函式式的function 6 console.log b 字串function 7 console.log typeof a function 8 c...

js物件 陣列轉換字串

物件轉換成字串需要使用tostring 方法。1 var a function 4 var b a.tostring 5 console.log a 函式式的function 6 console.log b 字串function 7 console.log typeof a function 8 c...

js 把字串陣列轉換為陣列

在對接的過程中,後台傳來的資料其中有乙個是陣列字串,這時候就需要解析成純陣列了。使用json.parse 可以解析 let str abc def console.log str string json.parse str console.log str abc def 字串 2 abc def 陣...