数组转字符串:
var list = ['a','b','c'] var listString = list.join(',') //变成字符串后,以逗号分隔 console.log(listString)
字符串转数组:
var string = '1,2' var list = string.split(',') //字符串按逗号分隔成数组 console.log(list)
字符串转数字:
var string = '9' var numberType = string - 0 console.log(typeof numberType) //typeof 查看数据类型
数字类型转字符串:
var number = 9 var stringType = number.toString() console.log(typeof stringType) //typeof 查看数据类型
object类型转字符串
var data = { id:0 } var stringData = JSON.stringify(data)
字符串转object
var data = "{"id":0"}" var str = JSON.parse(data)