简体   繁体   English

从对象创建数组-ES6

[英]Create Array from Object - ES6

Can I create an Array from an Object just in one line? 我可以只一行就从一个对象创建一个数组吗? I don't want all the values object, just a selection: 我不希望所有的值对象,只是一个选择:

 const myObject = { a: 'foo', b: 'bar', c:'yep' } const { a, c } = myObject const myArray = Array.of(a, c) console.log(myArray) 

Could I use destructuring in some way inside the Array.of parameter? 我可以在Array.of参数内以某种方式使用解构吗?

Why not just : 为什么不只是:

const myObject = { a: 'foo', b: 'bar', c:'yep' };
let arr = Array.of(myObject.a, myObject.c);
console.log(arr);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM