简单JS问题总结

1、用JS写一个函数,查询字符串中'hello'的所有位置?

function find(string, findString){
  let arr = []
  let index = 0
  let result = string.indexOf(findString, index)
  while(result != -1){
    arr.push(result)
    index = result + 1
    result = string.indexOf(findString, index)
  }
  return result
}

2、用JS写一个函数,查询字符串中最长的单词?

function findLongest(str){
  let arr = str.split(' ')
  let maxLength = 0
  for(let i=0; i maxLength){
      maxLength = arr[i].length
    }
  }
  return maxLength
}

3、原型继承
原型链:

function Animal(){
  this.body = '肉体'
}
Animal.prototype.move = function(){}

function Human(){
  Animal.apply(this, arguments)
  this.name = name
}

let f = function(){}
f.prototype = Animal.prototype
Human.prototype = new f()

4、css中em、rem、px区别?
px:在缩放页面时无法调整那些使用px作为单位的字体、按钮的大小
em:em的值是不固定的,会继承父级元素字体大小,代表倍数
rem:rem的值也是不固定的,他始终是基于根元素,也代表倍数

你可能感兴趣的:(简单JS问题总结)