标签:方便 数组 www 函数式编程 ie9 define 通过 string 跳出循环
let list = [‘a‘, ‘b‘, ‘c‘, ‘d‘,‘e‘]; for (var i = 0; i < list.length; i++) { console.log(list[i]) }
// a、b、c、d、e
let list = [‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘]; for (var i = list.length - 1; i > 0; i--) { if (i === 0) { continue; } if (i === 2) { break; } console.log(list[i]) }
// e、d
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘]; let i = 0; while (i < list.length){ console.log(list[i]); i++ } //‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘]; let i = 0; do { console.log(list[i]) i++; } while (i < list.length) //‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘
let list = [‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘]; list.forEach((item,index,ary) => { console.log(`item:${item}----index:${index}----ary:${ary}`) })
item:a----index:0----ary:a,b,c,d,e
item:b----index:1----ary:a,b,c,d,e
item:c----index:2----ary:a,b,c,d,e
item:d----index:3----ary:a,b,c,d,e
item:e----index:4----ary:a,b,c,d,e
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘]; const isPass = list.every((item,index) => { return typeof item === ‘string‘ }) console.log(isPass) // false
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘]; const isPass = list.some((item,index) => { return typeof item === ‘boolean‘ }) console.log(isPass) //false
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘,‘a‘]; const result = list.indexOf(‘a2‘,2) console.log(result) // 5
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘,‘a‘]; const result = list.lastIndexOf(‘a‘,2) console.log(result) //0
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘]; const result = list.filter((item, index) => { return typeof item === ‘string‘ }) console.log(result) // ["a", "c", "d", "e", "a"]
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘]; const result = list.map((item, index) => { return item + ‘_‘ }) console.log(result) // ["a_", "12_", "c_", "d_", "e_", "a_"]
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘]; const result = list.reduce((total,prev,index,arr) => { return total + prev; },‘‘); console.log(‘result‘,result); //a12cdea
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘]; for(let key in list){ console.log(list[key]); } //‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘];
const result = list.find((item,index) => { return item === ‘a‘ }) console.log(result) // a
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘,‘a‘]; const result = list.findIndex((item,index) => { return item === ‘a‘ }) console.log(result) // 0
let list = [‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘]; for (let s of list) { console.log(s); } //‘a‘, 12, ‘c‘, ‘d‘, ‘e‘, ‘a‘
标签:方便 数组 www 函数式编程 ie9 define 通过 string 跳出循环
原文地址:https://www.cnblogs.com/liangfc/p/12858325.html