RE: RE: JavaScript开发笔记
You are viewing a single comment's thread from:

RE: JavaScript开发笔记

Words
0
Reading
0 min
Listen
Play
7M
<input type="text" v-model="keywords" placeholder="搜索">
<tr v-for="list in search(keywords)"></tr>

//第一种方法 filter + includes

search(keywords){
  return this.lists.filter(item => {
    if(item.name.includes(keywords)){
      return item
    }
  })
}

steemposts.forEach(item => {
  if( JSON.parse(item.json_metadata).tags.includes('starnote')){
      res.push(item)
      console.log(111, 'okok!')
  }
})

let res = steemposts.filter(item => {
  if( JSON.parse(item.json_metadata).tags.includes('starnote') ){
      console.log(111, 'okok!')
      return item
  }
})


//检测数组 site 是否包含 runoob :
let site = ['runoob', 'google', 'taobao'];
 site.includes('runoob'); 
// true 
 site.includes('baidu'); 
// false

//第二种方法 indexOf

indexOf()
    array.indexOf(item,start) 
     
    item 
    start 0  stringObject.length - 1
if(arr.indexOf() > -1){//则包含该元素}

let fruits=["Banana","Orange","Apple","Mango","Banana","Orange","Apple"]
let a = fruits.indexOf("Apple")
console.log(123, a)  //2

search(keywords){
  let newlists=[]
  this.lists.forEach(item => {
    if(item.name.indexOf(keywords) != -1){
      newlists.push(item)
    }
  })
  return newlists
}

string.indexOf()
   使 lastIndexOf() 
@lemooljiang: <input | Ecency