加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React-Native ES6使用语法和underscore的使用

发布时间:2020-12-15 07:19:20 所属栏目:百科 来源:网络整理
导读:1、获取对象的键值 es6:let a = { 'a1' : '1' , 'a2' : '2' }Object. keys ( a ) // ["a1","a2"] Object.values( a ) // ["1","2"] underscore:let keys = _ . keys ({one: 1 ,two: 2 ,three: 3 });console. log ( keys ); // [ "one" , "two" , "three" ]le

1、获取对象的键值

es6:
let a = {'a1':'1','a2':'2'}
Object.keys(a) // ["a1","a2"]
Object.values(a) // ["1","2"]
underscore:
let keys = _.keys({one: 1,two: 2,three: 3});
console.log(keys);
// ["one","two","three"]
let values = _.values({one: 1,three: 3});
// [1,2,3]

2、数组的遍历
es6:

// forEach方法
[1,3,4].forEach((x,i)=>{console.log(x,i)}) // 1 0 2 1 3 2 4 3
// filter方法
[1,4].filter(value=>value>2)
// [3,4]
// map方法
[1,4].map(x=> x*2);
// [2,4,6,8]
// join方法
[1,4].join('#')
// "1#2#3#4"
// toString方法
[1,2,3,4].toString()
// "1,4"
// fill方法
new Array(3).fill('a')
// ["a","a","a"]

underscore:

// each
_.each([1,4],(value,idx)=>console.log(value,idx)); // 1 0 2 1 3 2 4 3 
// filter
let newArr = _.filter([1,(value)=>{return value>2}); console.log(newArr); // [3,4]
// map 方法
console.log(_.map([1,(value)=>{return value*2})); // [2,8]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读