var value ='25'var number =Number(value)// 转型函数,转成Number类型
console.log(typeof number)// numbervar obj =newNumber(value)// 构造函数,构造Number对象实例
console.log(typeof obj)// object
Boolean 类型
var booleanObject =newBoolean(true)// 调用Boolean构造函数,并传入true/false
console.log(stringObject.indexOf('o'))// 4
console.log(stringObject.lastIndexOf('o'))// 7
console.log(stringObject.indexOf('o',6))// 7,第二个参数表示从哪个位置开始搜索
console.log(stringObject.lastIndexOf('o',6))// 4,第二个参数表示从哪个位置开始搜索var loremString ='Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'var position =newArray()var pos = loremString.indexOf('o')while(pos >-1){
position.push(pos)
pos = loremString.indexOf('o', pos +1)}
console.log(position)// 所有包含o的字符位置集合
trim()方法
返回值
trim()
创建副本,删除前置后缀空格,返回副本
trimLeft()
创建副本,删除前置空格,返回副本
trimRight()
创建副本,删除后缀空格,返回副本
var stringValue =' hello world 'var trimStringValue = stringValue.trim()
console.log(stringValue)// " hello world "
console.log(trimStringValue)// "hello world"
var stringCompare ='yellow'
console.log(stringCompare.localeCompare('brick'))// 1,brick字母表在yellow之前
console.log(stringCompare.localeCompare('yellow'))// 0,yellow字母表与yellow相同
console.log(stringCompare.localeCompare('zoo'))// -1,zoo字母表在yellow之后functiondetermineOrder(value){var result = stringCompare.localeCompare(value)
result <0&&
console.log(`The string 'yellow' comes before the string ${value}.`)
result >0&&
console.log(`The string 'yellow' comes after the string ${value}.`)
result ===0&&
console.log(`The string 'yellow' is equal to the string ${value}.`)}determineOrder('brick')// "The string 'yellow' comes after the string brick."determineOrder('yellow')// "The string 'yellow' is equal to the string zoo."determineOrder('zoo')// "The string 'yellow' comes before the string zoo."