number | string | array conversion

number


number => string => arr

let a = 123

a.toString()   // "123"

let str = a.toString().split()   // ["123"]
let arr = a.toString().split('')   // ["1", "2", "3"]

Description:

  • .toString()(Brackets no parameters), the 数字conversion into字符串
  • .split()Put 字符串into数组

arr => string = > number

const arr = [1, 2, 3]

console.log(arr.join(''))   // "123"
console.log(parseInt(arr.join('')))   // 123

Description:

  • .join()Connection parameter indicates a character, the 数组transformation into字符串
  • parseInt()Put 字符串into数字
Published 23 original articles · won praise 0 · Views 570

Guess you like

Origin blog.csdn.net/JIANLI0123/article/details/103421520