简体   繁体   中英

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?

Why not just :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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